feat: 添加通知管理功能,包括服务层逻辑和HTTP API处理。

This commit is contained in:
2026-01-28 09:05:07 +08:00
parent e29c808451
commit a18564c2d8
2 changed files with 26 additions and 5 deletions

View File

@@ -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)