f
This commit is contained in:
108
internal/infrastructure/http/routes/product_routes.go
Normal file
108
internal/infrastructure/http/routes/product_routes.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"hyapi-server/internal/infrastructure/http/handlers"
|
||||
component_report "hyapi-server/internal/shared/component_report"
|
||||
sharedhttp "hyapi-server/internal/shared/http"
|
||||
"hyapi-server/internal/shared/middleware"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// ProductRoutes 产品路由
|
||||
type ProductRoutes struct {
|
||||
productHandler *handlers.ProductHandler
|
||||
componentReportHandler *component_report.ComponentReportHandler
|
||||
auth *middleware.JWTAuthMiddleware
|
||||
optionalAuth *middleware.OptionalAuthMiddleware
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewProductRoutes 创建产品路由
|
||||
func NewProductRoutes(
|
||||
productHandler *handlers.ProductHandler,
|
||||
componentReportHandler *component_report.ComponentReportHandler,
|
||||
auth *middleware.JWTAuthMiddleware,
|
||||
optionalAuth *middleware.OptionalAuthMiddleware,
|
||||
logger *zap.Logger,
|
||||
) *ProductRoutes {
|
||||
return &ProductRoutes{
|
||||
productHandler: productHandler,
|
||||
componentReportHandler: componentReportHandler,
|
||||
auth: auth,
|
||||
optionalAuth: optionalAuth,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// Register 注册产品相关路由
|
||||
func (r *ProductRoutes) Register(router *sharedhttp.GinRouter) {
|
||||
engine := router.GetEngine()
|
||||
|
||||
// 数据大厅 - 公开接口
|
||||
products := engine.Group("/api/v1/products")
|
||||
{
|
||||
// 获取产品列表(分页+筛选)
|
||||
products.GET("", r.optionalAuth.Handle(), r.productHandler.ListProducts)
|
||||
|
||||
// 获取产品统计
|
||||
products.GET("/stats", r.productHandler.GetProductStats)
|
||||
|
||||
// 根据产品代码获取API配置
|
||||
products.GET("/code/:product_code/api-config", r.productHandler.GetProductApiConfigByCode)
|
||||
|
||||
// 产品详情和API配置 - 使用具体路径避免冲突
|
||||
products.GET("/:id", r.productHandler.GetProductDetail)
|
||||
products.GET("/:id/api-config", r.productHandler.GetProductApiConfig)
|
||||
products.GET("/:id/documentation", r.productHandler.GetProductDocumentation)
|
||||
products.GET("/:id/documentation/download", r.productHandler.DownloadProductDocumentation)
|
||||
|
||||
// 订阅产品(需要认证)
|
||||
products.POST("/:id/subscribe", r.auth.Handle(), r.productHandler.SubscribeProduct)
|
||||
}
|
||||
|
||||
// 组件报告 - 需要认证
|
||||
componentReport := engine.Group("/api/v1/component-report", r.auth.Handle())
|
||||
{
|
||||
// 生成并下载 example.json 文件
|
||||
componentReport.POST("/download-example-json", r.componentReportHandler.DownloadExampleJSON)
|
||||
// 生成并下载示例报告ZIP文件
|
||||
componentReport.POST("/generate-and-download", r.componentReportHandler.GenerateAndDownloadZip)
|
||||
}
|
||||
|
||||
// 产品组件报告相关接口 - 已迁移到 ComponentReportOrderRoutes
|
||||
|
||||
// 分类 - 公开接口
|
||||
categories := engine.Group("/api/v1/categories")
|
||||
{
|
||||
// 获取分类列表
|
||||
categories.GET("", r.productHandler.ListCategories)
|
||||
|
||||
// 获取分类详情
|
||||
categories.GET("/:id", r.productHandler.GetCategoryDetail)
|
||||
}
|
||||
|
||||
// 我的订阅 - 需要认证
|
||||
my := engine.Group("/api/v1/my", r.auth.Handle())
|
||||
{
|
||||
subscriptions := my.Group("/subscriptions")
|
||||
{
|
||||
// 获取我的订阅列表
|
||||
subscriptions.GET("", r.productHandler.ListMySubscriptions)
|
||||
|
||||
// 获取我的订阅统计
|
||||
subscriptions.GET("/stats", r.productHandler.GetMySubscriptionStats)
|
||||
|
||||
// 获取订阅详情
|
||||
subscriptions.GET("/:id", r.productHandler.GetMySubscriptionDetail)
|
||||
|
||||
// 获取订阅使用情况
|
||||
subscriptions.GET("/:id/usage", r.productHandler.GetMySubscriptionUsage)
|
||||
|
||||
// 取消订阅
|
||||
subscriptions.POST("/:id/cancel", r.productHandler.CancelMySubscription)
|
||||
}
|
||||
}
|
||||
|
||||
r.logger.Info("产品路由注册完成")
|
||||
}
|
||||
Reference in New Issue
Block a user