All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m26s
69 lines
3.4 KiB
Go
69 lines
3.4 KiB
Go
package routes
|
||
|
||
import (
|
||
"github.com/gofiber/fiber/v2"
|
||
|
||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||
)
|
||
|
||
// registerNotificationRoutes 注册当前后台账号的站内通知路由。
|
||
func registerNotificationRoutes(router fiber.Router, handler *admin.NotificationHandler, doc *openapi.Generator, basePath string) {
|
||
notifications := router.Group("/notifications")
|
||
groupPath := basePath + "/notifications"
|
||
|
||
// 静态路径必须先于通知 ID 动态路径,避免被动态参数吞掉。
|
||
Register(notifications, doc, groupPath, "GET", "/unread-count", handler.UnreadCount, RouteSpec{
|
||
Summary: "查询通知未读数",
|
||
Description: "仅查询当前认证后台账号的未过期未读通知,超过 99 条时 display_count 返回 99+。",
|
||
Tags: []string{"站内通知"},
|
||
Output: new(dto.NotificationUnreadCountResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(notifications, doc, groupPath, "GET", "/unread-summary", handler.UnreadSummary, RouteSpec{
|
||
Summary: "查询通知未读分类汇总",
|
||
Description: "返回当前认证后台账号未过期通知的总未读数及审批、临期、同步、系统四个固定类别计数。",
|
||
Tags: []string{"站内通知"},
|
||
Output: new(dto.NotificationUnreadSummaryResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(notifications, doc, groupPath, "GET", "", handler.List, RouteSpec{
|
||
Summary: "查询通知列表",
|
||
Description: "仅返回当前认证后台账号的未过期通知,固定按创建时间和通知 ID 倒序。ref_type/ref_id/ref_key 是受控资源引用,不是前端路由;点击通知时应调用 GET /api/admin/notifications/{id}/target,以返回的 target_type 和 available 决定是否跳转。",
|
||
Tags: []string{"站内通知"},
|
||
Input: new(dto.NotificationListRequest),
|
||
Output: new(dto.NotificationListResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(notifications, doc, groupPath, "PUT", "/read-all", handler.MarkAllRead, RouteSpec{
|
||
Summary: "批量标记通知已读",
|
||
Description: "类别为空时更新当前认证后台账号全部未过期未读通知;指定有效类别时只更新该类别,重复调用幂等成功。",
|
||
Tags: []string{"站内通知"},
|
||
Input: new(dto.NotificationReadAllRequest),
|
||
Output: new(dto.NotificationReadAllResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(notifications, doc, groupPath, "GET", "/:id/target", handler.Target, RouteSpec{
|
||
Summary: "解析通知受控目标",
|
||
Description: "先校验通知属于当前认证后台账号,再复核目标资源当前权限;只返回白名单结构化目标,不返回任意 URL。前端维护 target_type 到页面的白名单映射;available=false 或 target_type 为空时只展示通知正文,不执行跳转。",
|
||
Tags: []string{"站内通知"},
|
||
Input: new(dto.NotificationIDParams),
|
||
Output: new(dto.NotificationTargetResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(notifications, doc, groupPath, "PUT", "/:id/read", handler.MarkRead, RouteSpec{
|
||
Summary: "标记单条通知已读",
|
||
Description: "仅更新当前认证后台账号的通知;通知不存在、属于别人或已经已读均幂等成功。",
|
||
Tags: []string{"站内通知"},
|
||
Input: new(dto.NotificationIDParams),
|
||
Output: new(dto.NotificationReadResponse),
|
||
Auth: true,
|
||
})
|
||
}
|