feat: 添加通知管理功能,包括服务层逻辑和HTTP API处理。
This commit is contained in:
@@ -185,10 +185,31 @@ func (h *NotificationHandler) DeleteNotification(c *gin.Context) {
|
|||||||
api.NoContent(c)
|
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
|
// RegisterRoutes registers all notification routes to the given router group
|
||||||
func (h *NotificationHandler) RegisterRoutes(rg *gin.RouterGroup) {
|
func (h *NotificationHandler) RegisterRoutes(rg *gin.RouterGroup) {
|
||||||
notifications := rg.Group("/notifications")
|
notifications := rg.Group("/notifications")
|
||||||
{
|
{
|
||||||
|
notifications.POST("", h.CreateNotification)
|
||||||
notifications.GET("", h.GetNotifications)
|
notifications.GET("", h.GetNotifications)
|
||||||
notifications.GET("/unread-count", h.GetUnreadCount)
|
notifications.GET("/unread-count", h.GetUnreadCount)
|
||||||
notifications.PUT("/:id/read", h.MarkAsRead)
|
notifications.PUT("/:id/read", h.MarkAsRead)
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ func NewNotificationService(repo *repository.NotificationRepository) *Notificati
|
|||||||
|
|
||||||
// CreateNotificationInput represents input for creating a notification
|
// CreateNotificationInput represents input for creating a notification
|
||||||
type CreateNotificationInput struct {
|
type CreateNotificationInput struct {
|
||||||
UserID uint
|
UserID uint `json:"user_id" binding:"required"`
|
||||||
Type models.NotificationType
|
Type models.NotificationType `json:"type" binding:"required"`
|
||||||
Title string
|
Title string `json:"title" binding:"required"`
|
||||||
Content string
|
Content string `json:"content" binding:"required"`
|
||||||
RelatedID *uint
|
RelatedID *uint `json:"related_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateNotification creates a new notification
|
// CreateNotification creates a new notification
|
||||||
|
|||||||
Reference in New Issue
Block a user