Files
junhong_cmp_fiber/cmd/api/docs.go
huang fdcff33058
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m9s
feat: 实现企业卡授权和授权记录管理功能
主要功能:
- 添加企业卡授权/回收接口 (POST /enterprises/:id/allocate-cards, recall-cards)
- 添加授权记录管理接口 (GET/PUT /authorizations)
- 实现代理用户数据权限过滤(只能查看自己店铺下企业的授权记录)
- 添加 GORM callback 支持授权记录表的数据权限过滤

技术改进:
- 原生 SQL 查询手动添加数据权限过滤(ListWithJoin, GetByIDWithJoin)
- 移除卡授权预检接口(allocate-cards/preview),保留内部方法
- 完善单元测试和集成测试覆盖
2026-01-26 15:07:03 +08:00

59 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
"github.com/break/junhong_cmp_fiber/internal/handler/h5"
"github.com/break/junhong_cmp_fiber/internal/routes"
"github.com/break/junhong_cmp_fiber/pkg/openapi"
)
// generateOpenAPIDocs 生成 OpenAPI 文档
// outputPath: 文档输出路径
// logger: 日志记录器
// 生成失败时记录错误但不影响程序继续运行
func generateOpenAPIDocs(outputPath string, logger *zap.Logger) {
// 1. 创建生成器
adminDoc := openapi.NewGenerator("君鸿卡管系统 API", "1.0.0")
// 2. 创建临时 Fiber App 用于路由注册
app := fiber.New()
// 3. 创建 Handler使用 nil 依赖,因为只需要路由结构)
handlers := &bootstrap.Handlers{
AdminAuth: admin.NewAuthHandler(nil, nil),
H5Auth: h5.NewAuthHandler(nil, nil),
Account: admin.NewAccountHandler(nil),
Role: admin.NewRoleHandler(nil),
Permission: admin.NewPermissionHandler(nil),
Shop: admin.NewShopHandler(nil),
ShopAccount: admin.NewShopAccountHandler(nil),
ShopCommission: admin.NewShopCommissionHandler(nil),
CommissionWithdrawal: admin.NewCommissionWithdrawalHandler(nil),
CommissionWithdrawalSetting: admin.NewCommissionWithdrawalSettingHandler(nil),
Enterprise: admin.NewEnterpriseHandler(nil),
EnterpriseCard: admin.NewEnterpriseCardHandler(nil),
Authorization: admin.NewAuthorizationHandler(nil),
CustomerAccount: admin.NewCustomerAccountHandler(nil),
MyCommission: admin.NewMyCommissionHandler(nil),
IotCard: admin.NewIotCardHandler(nil),
IotCardImport: admin.NewIotCardImportHandler(nil),
AssetAllocationRecord: admin.NewAssetAllocationRecordHandler(nil),
Storage: admin.NewStorageHandler(nil),
}
// 4. 注册所有路由到文档生成器
routes.RegisterRoutesWithDoc(app, handlers, &bootstrap.Middlewares{}, adminDoc)
// 6. 保存规范到指定路径
if err := adminDoc.Save(outputPath); err != nil {
logger.Error("生成 OpenAPI 文档失败", zap.String("path", outputPath), zap.Error(err))
return
}
logger.Info("OpenAPI 文档生成成功", zap.String("path", outputPath))
}