feat: 新增通知系统,支持通知列表、未读计数、标记已读、删除、创建和广播功能,并引入管理员中间件和用户仓库。
This commit is contained in:
@@ -205,6 +205,34 @@ func (h *NotificationHandler) CreateNotification(c *gin.Context) {
|
||||
api.Created(c, notification)
|
||||
}
|
||||
|
||||
// BroadcastNotification handles POST /api/v1/notifications/broadcast
|
||||
// Sends a notification to all active users
|
||||
func (h *NotificationHandler) BroadcastNotification(c *gin.Context) {
|
||||
// TODO: Add strict admin authorization check
|
||||
|
||||
var input service.BroadcastNotificationInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
api.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Validate input
|
||||
if input.Title == "" || input.Content == "" {
|
||||
api.BadRequest(c, "Title and content are required")
|
||||
return
|
||||
}
|
||||
if input.Type == "" {
|
||||
input.Type = models.NotificationTypeSystem
|
||||
}
|
||||
|
||||
if err := h.notificationService.BroadcastNotification(input); err != nil {
|
||||
api.InternalError(c, "Failed to broadcast notification: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
api.Success(c, gin.H{"message": "Notification broadcast started"})
|
||||
}
|
||||
|
||||
// RegisterUserRoutes registers notification routes for regular users
|
||||
func (h *NotificationHandler) RegisterUserRoutes(rg *gin.RouterGroup) {
|
||||
notifications := rg.Group("/notifications")
|
||||
@@ -222,5 +250,6 @@ func (h *NotificationHandler) RegisterAdminRoutes(rg *gin.RouterGroup) {
|
||||
notifications := rg.Group("/notifications")
|
||||
{
|
||||
notifications.POST("", h.CreateNotification)
|
||||
notifications.POST("/broadcast", h.BroadcastNotification)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user