package routes import ( "tyapi-server/internal/infrastructure/http/handlers" sharedhttp "tyapi-server/internal/shared/http" "tyapi-server/internal/shared/middleware" ) // ProductAdminRoutes 产品管理员路由 type ProductAdminRoutes struct { handler *handlers.ProductAdminHandler auth *middleware.JWTAuthMiddleware admin *middleware.AdminAuthMiddleware } // NewProductAdminRoutes 创建产品管理员路由 func NewProductAdminRoutes( handler *handlers.ProductAdminHandler, auth *middleware.JWTAuthMiddleware, admin *middleware.AdminAuthMiddleware, ) *ProductAdminRoutes { return &ProductAdminRoutes{ handler: handler, auth: auth, admin: admin, } } // Register 注册路由 func (r *ProductAdminRoutes) Register(router *sharedhttp.GinRouter) { // 管理员路由组 engine := router.GetEngine() adminGroup := engine.Group("/api/v1/admin") adminGroup.Use(r.admin.Handle()) // 管理员权限验证 { // 产品管理 products := adminGroup.Group("/products") { products.GET("", r.handler.ListProducts) products.GET("/available", r.handler.GetAvailableProducts) products.GET("/:id", r.handler.GetProductDetail) products.POST("", r.handler.CreateProduct) products.PUT("/:id", r.handler.UpdateProduct) products.DELETE("/:id", r.handler.DeleteProduct) // 组合包管理 products.POST("/:id/package-items", r.handler.AddPackageItem) products.PUT("/:id/package-items/:item_id", r.handler.UpdatePackageItem) products.DELETE("/:id/package-items/:item_id", r.handler.RemovePackageItem) products.PUT("/:id/package-items/reorder", r.handler.ReorderPackageItems) products.PUT("/:id/package-items/batch", r.handler.UpdatePackageItems) // API配置管理 products.GET("/:id/api-config", r.handler.GetProductApiConfig) products.POST("/:id/api-config", r.handler.CreateProductApiConfig) products.PUT("/:id/api-config", r.handler.UpdateProductApiConfig) products.DELETE("/:id/api-config", r.handler.DeleteProductApiConfig) } // 分类管理 categories := adminGroup.Group("/product-categories") { categories.GET("", r.handler.ListCategories) categories.GET("/:id", r.handler.GetCategoryDetail) categories.POST("", r.handler.CreateCategory) categories.PUT("/:id", r.handler.UpdateCategory) categories.DELETE("/:id", r.handler.DeleteCategory) } // 订阅管理 subscriptions := adminGroup.Group("/subscriptions") { subscriptions.GET("", r.handler.ListSubscriptions) subscriptions.GET("/stats", r.handler.GetSubscriptionStats) subscriptions.PUT("/:id/price", r.handler.UpdateSubscriptionPrice) } } }