Files
ai-agent/internal/controllers/dashboard/notification_controller.go
T
mlogclub 79614b2d07 Refactor import paths to use internal/pkg/httpx/params
- Updated multiple repository and service files to replace imports from "github.com/mlogclub/simple/web/params" with "cs-agent/internal/pkg/httpx/params".
- Adjusted context handling in auth_service and ws_service to use gin.Context instead of iris.Context.
- Ensured consistent usage of HTTP status responses across websocket handlers.
2026-05-23 22:10:20 +08:00

83 lines
2.3 KiB
Go

package dashboard
import (
"strings"
"cs-agent/internal/builders"
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
type NotificationController struct {
Ctx *gin.Context
}
func (c *NotificationController) AnyList() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionNotificationView)
if err != nil {
return web.JsonError(err)
}
cnd := params.NewPagedSqlCnd(c.Ctx,
params.QueryFilter{ParamName: "type", ColumnName: "notification_type"},
).Eq("recipient_user_id", operator.UserID).
Eq("status", enums.StatusOk).
Desc("id")
switch strings.TrimSpace(c.Ctx.Query("readStatus")) {
case "unread":
cnd.Where("read_at IS NULL")
case "read":
cnd.Where("read_at IS NOT NULL")
}
list, paging := services.NotificationService.FindPageByCnd(cnd)
return web.JsonData(&web.PageResult{
Results: builders.BuildNotificationList(list),
Page: paging,
})
}
func (c *NotificationController) GetUnread_count() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionNotificationView)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(&response.NotificationUnreadCountResponse{
UnreadCount: services.NotificationService.CountUnread(operator.UserID),
})
}
func (c *NotificationController) PostMark_read() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionNotificationUpdate)
if err != nil {
return web.JsonError(err)
}
req := request.MarkNotificationReadRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
if err := services.NotificationService.MarkRead(req.ID, operator.UserID); err != nil {
return web.JsonError(err)
}
return web.JsonSuccess()
}
func (c *NotificationController) PostMark_all_read() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionNotificationUpdate)
if err != nil {
return web.JsonError(err)
}
if err := services.NotificationService.MarkAllRead(operator.UserID); err != nil {
return web.JsonError(err)
}
return web.JsonSuccess()
}