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/constants" "github.com/break/junhong_cmp_fiber/pkg/errors" "github.com/break/junhong_cmp_fiber/pkg/middleware" "github.com/break/junhong_cmp_fiber/pkg/openapi" ) func registerCarrierRoutes(router fiber.Router, handler *admin.CarrierHandler, doc *openapi.Generator, basePath string) { // 通道阈值命中记录使用顶层路径,避免与 /carriers/:id 的参数路由冲突; // 门禁沿用超管/平台路由组级 gate 先例(代理、企业与其他账号统一 403), // 并挂在功能路径组上:Fiber 的组中间件按路径前缀生效。 hitGate := func(c *fiber.Ctx) error { userType := middleware.GetUserTypeFromContext(c.UserContext()) if userType != constants.UserTypeSuperAdmin && userType != constants.UserTypePlatform { return errors.New(errors.CodeForbidden, constants.PlatformManagementForbiddenMessage) } return c.Next() } hits := router.Group("/carrier-traffic-threshold-hits", hitGate) hitsPath := basePath + "/carrier-traffic-threshold-hits" Register(hits, doc, hitsPath, "GET", "", handler.ListThresholdHits, RouteSpec{ Summary: "查询通道阈值命中记录", Description: "返回达量停机时冻结的数字证据:命中时该卡当前周期的累计流量读数、本次判定实际生效的阈值与单位、" + "计费周期起点、判定时间与触发来源,以及周期恢复的解锁时间与复机结果;" + "阈值与读数为命中时值,之后修改通道阈值不改写历史命中;" + "本次上线前的历史行读数为空按「无」返回,判定时间取既有创建时间,不阻断查询。" + "支持按运营商通道、卡、计费周期起点精确匹配与判定时间闭区间(start_time/end_time,带时区 RFC3339 秒级)筛选," + "按判定时间倒序分页;仅超级管理员与平台账号可访问,并按卡数据范围过滤,越权与不存在不可区分," + "不返回凭证或上游响应原文", Tags: []string{"运营商管理"}, Input: new(dto.CarrierThresholdHitListRequest), Output: new(dto.CarrierThresholdHitPageResult), Auth: true, }) carriers := router.Group("/carriers") groupPath := basePath + "/carriers" Register(carriers, doc, groupPath, "GET", "", handler.List, RouteSpec{ Summary: "运营商列表", Tags: []string{"运营商管理"}, Input: new(dto.CarrierListRequest), Output: new(dto.CarrierPageResult), Auth: true, }) Register(carriers, doc, groupPath, "POST", "", handler.Create, RouteSpec{ Summary: "创建运营商", Tags: []string{"运营商管理"}, Input: new(dto.CreateCarrierRequest), Output: new(dto.CarrierResponse), Auth: true, }) Register(carriers, doc, groupPath, "GET", "/:id", handler.Get, RouteSpec{ Summary: "获取运营商详情", Tags: []string{"运营商管理"}, Input: new(dto.IDReq), Output: new(dto.CarrierResponse), Auth: true, }) Register(carriers, doc, groupPath, "PUT", "/:id", handler.Update, RouteSpec{ Summary: "更新运营商", Tags: []string{"运营商管理"}, Input: new(dto.UpdateCarrierParams), Output: new(dto.CarrierResponse), Auth: true, }) Register(carriers, doc, groupPath, "DELETE", "/:id", handler.Delete, RouteSpec{ Summary: "删除运营商", Tags: []string{"运营商管理"}, Input: new(dto.IDReq), Output: nil, Auth: true, }) Register(carriers, doc, groupPath, "PUT", "/:id/status", handler.UpdateStatus, RouteSpec{ Summary: "更新运营商状态", Tags: []string{"运营商管理"}, Input: new(dto.UpdateCarrierStatusParams), Output: nil, Auth: true, }) }