package v1 import ( "git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/internal/dto" "git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/internal/middleware" "git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/internal/service" "git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/pkg/app" "git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/pkg/errcode" "github.com/gin-gonic/gin" ) // NotificationHandler 通知推送接口。 type NotificationHandler struct { svc *service.NotificationService } // NewNotificationHandler 创建通知 handler。 func NewNotificationHandler() *NotificationHandler { return &NotificationHandler{svc: service.NewNotificationService()} } // Send 向单个用户发送系统通知。 func (h *NotificationHandler) Send(c *gin.Context) { response := app.NewResponse(c) var request dto.NotificationSendRequest if err := c.ShouldBindJSON(&request); err != nil { response.ToErrorResponse(errcode.InvalidParams.WithDetails(err.Error())) return } adminID, _ := middleware.GetAdminID(c.Request.Context()) if e := h.svc.Send(c.Request.Context(), adminID, &request); e != nil { response.ToErrorResponse(e) return } response.ToResponse(nil) } // Broadcast 全量广播系统通知。 func (h *NotificationHandler) Broadcast(c *gin.Context) { response := app.NewResponse(c) var request dto.NotificationBroadcastRequest if err := c.ShouldBindJSON(&request); err != nil { response.ToErrorResponse(errcode.InvalidParams.WithDetails(err.Error())) return } adminID, _ := middleware.GetAdminID(c.Request.Context()) out, e := h.svc.Broadcast(c.Request.Context(), adminID, &request) if e != nil { response.ToErrorResponse(e) return } response.ToResponse(out) }