fix
This commit is contained in:
@@ -243,6 +243,51 @@ func (h *ApiHandler) DecryptParams(c *gin.Context) {
|
||||
h.responseBuilder.Success(c, decryptedData, "解密成功")
|
||||
}
|
||||
|
||||
// GetFormConfig 获取指定API的表单配置
|
||||
// @Summary 获取表单配置
|
||||
// @Description 获取指定API的表单配置,用于前端动态生成表单
|
||||
// @Tags API调试
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security Bearer
|
||||
// @Param api_code path string true "API代码"
|
||||
// @Success 200 {object} map[string]interface{} "获取成功"
|
||||
// @Failure 400 {object} map[string]interface{} "请求参数错误"
|
||||
// @Failure 401 {object} map[string]interface{} "未授权"
|
||||
// @Failure 404 {object} map[string]interface{} "API接口不存在"
|
||||
// @Router /api/v1/form-config/{api_code} [get]
|
||||
func (h *ApiHandler) GetFormConfig(c *gin.Context) {
|
||||
userID := h.getCurrentUserID(c)
|
||||
if userID == "" {
|
||||
h.responseBuilder.Unauthorized(c, "用户未登录")
|
||||
return
|
||||
}
|
||||
|
||||
apiCode := c.Param("api_code")
|
||||
if apiCode == "" {
|
||||
h.responseBuilder.BadRequest(c, "API代码不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
h.logger.Info("获取表单配置", zap.String("api_code", apiCode), zap.String("user_id", userID))
|
||||
|
||||
// 获取表单配置
|
||||
config, err := h.appService.GetFormConfig(c.Request.Context(), apiCode)
|
||||
if err != nil {
|
||||
h.logger.Error("获取表单配置失败", zap.String("api_code", apiCode), zap.String("user_id", userID), zap.Error(err))
|
||||
h.responseBuilder.BadRequest(c, "获取表单配置失败")
|
||||
return
|
||||
}
|
||||
|
||||
if config == nil {
|
||||
h.responseBuilder.BadRequest(c, "API接口不存在")
|
||||
return
|
||||
}
|
||||
|
||||
h.logger.Info("获取表单配置成功", zap.String("api_code", apiCode), zap.String("user_id", userID), zap.Int("field_count", len(config.Fields)))
|
||||
h.responseBuilder.Success(c, config, "获取表单配置成功")
|
||||
}
|
||||
|
||||
// getCurrentUserID 获取当前用户ID
|
||||
func (h *ApiHandler) getCurrentUserID(c *gin.Context) string {
|
||||
if userID, exists := c.Get("user_id"); exists {
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
// ApiRoutes API路由注册器
|
||||
type ApiRoutes struct {
|
||||
apiHandler *handlers.ApiHandler
|
||||
authMiddleware *middleware.JWTAuthMiddleware
|
||||
apiHandler *handlers.ApiHandler
|
||||
authMiddleware *middleware.JWTAuthMiddleware
|
||||
domainAuthMiddleware *middleware.DomainAuthMiddleware
|
||||
logger *zap.Logger
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewApiRoutes 创建API路由注册器
|
||||
@@ -24,10 +24,10 @@ func NewApiRoutes(
|
||||
logger *zap.Logger,
|
||||
) *ApiRoutes {
|
||||
return &ApiRoutes{
|
||||
apiHandler: apiHandler,
|
||||
authMiddleware: authMiddleware,
|
||||
apiHandler: apiHandler,
|
||||
authMiddleware: authMiddleware,
|
||||
domainAuthMiddleware: domainAuthMiddleware,
|
||||
logger: logger,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ func (r *ApiRoutes) Register(router *sharedhttp.GinRouter) {
|
||||
{
|
||||
apiGroup.POST("/:api_name", r.domainAuthMiddleware.Handle(""), r.apiHandler.HandleApiCall)
|
||||
|
||||
// 表单配置接口(用于前端动态生成表单)
|
||||
apiGroup.GET("/form-config/:api_code", r.authMiddleware.Handle(), r.apiHandler.GetFormConfig)
|
||||
|
||||
// 加密接口(用于前端调试)
|
||||
apiGroup.POST("/encrypt", r.authMiddleware.Handle(), r.apiHandler.EncryptParams)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user