From a18564c2d8498fe73bf7f5a8b5296ebf192eb2ff Mon Sep 17 00:00:00 2001 From: admin <1297598740@qq.com> Date: Wed, 28 Jan 2026 09:05:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8C=85=E6=8B=AC?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=B1=82=E9=80=BB=E8=BE=91=E5=92=8CHTTP=20AP?= =?UTF-8?q?I=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/notification_handler.go | 21 +++++++++++++++++++++ internal/service/notification_service.go | 10 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/internal/handler/notification_handler.go b/internal/handler/notification_handler.go index a81d296..f67cb7f 100644 --- a/internal/handler/notification_handler.go +++ b/internal/handler/notification_handler.go @@ -185,10 +185,31 @@ func (h *NotificationHandler) DeleteNotification(c *gin.Context) { api.NoContent(c) } +// CreateNotification handles POST /api/v1/notifications +// Creates a new notification (Admin/System use) +func (h *NotificationHandler) CreateNotification(c *gin.Context) { + // TODO: Add admin authorization check + + var input service.CreateNotificationInput + if err := c.ShouldBindJSON(&input); err != nil { + api.BadRequest(c, "Invalid request body: "+err.Error()) + return + } + + notification, err := h.notificationService.CreateNotification(input) + if err != nil { + api.InternalError(c, "Failed to create notification: "+err.Error()) + return + } + + api.Created(c, notification) +} + // RegisterRoutes registers all notification routes to the given router group func (h *NotificationHandler) RegisterRoutes(rg *gin.RouterGroup) { notifications := rg.Group("/notifications") { + notifications.POST("", h.CreateNotification) notifications.GET("", h.GetNotifications) notifications.GET("/unread-count", h.GetUnreadCount) notifications.PUT("/:id/read", h.MarkAsRead) diff --git a/internal/service/notification_service.go b/internal/service/notification_service.go index e05a6dc..a75125f 100644 --- a/internal/service/notification_service.go +++ b/internal/service/notification_service.go @@ -25,11 +25,11 @@ func NewNotificationService(repo *repository.NotificationRepository) *Notificati // CreateNotificationInput represents input for creating a notification type CreateNotificationInput struct { - UserID uint - Type models.NotificationType - Title string - Content string - RelatedID *uint + UserID uint `json:"user_id" binding:"required"` + Type models.NotificationType `json:"type" binding:"required"` + Title string `json:"title" binding:"required"` + Content string `json:"content" binding:"required"` + RelatedID *uint `json:"related_id"` } // CreateNotification creates a new notification