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 {
|
||||
|
||||
Reference in New Issue
Block a user