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