refactor(handler): 重构runner及checker架构
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/ssdomei232/goodBaby/api/user"
|
||||
"github.com/ssdomei232/goodBaby/handler/db"
|
||||
"github.com/ssdomei232/goodBaby/internal/ruleConfigChecker"
|
||||
"github.com/ssdomei232/goodBaby/model"
|
||||
)
|
||||
|
||||
@@ -53,6 +55,23 @@ func HandleCreateRule(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if newRule.Type == "" {
|
||||
c.JSON(400, gin.H{"code": 400, "data": "规则类型不能为空"})
|
||||
return
|
||||
}
|
||||
|
||||
if newRule.Name == "" {
|
||||
c.JSON(400, gin.H{"code": 400, "data": "规则名称不能为空"})
|
||||
return
|
||||
}
|
||||
|
||||
// 规则校验
|
||||
validatorRegistry := ruleConfigChecker.InitValidatorRegistry()
|
||||
if err := validatorRegistry.Validate(newRule.Type, newRule.ConfigJson); err != nil {
|
||||
c.JSON(400, gin.H{"code": 400, "data": fmt.Sprintf("规则配置验证失败: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
newRule.UID = userInfo.ID
|
||||
result := gormDB.Create(&newRule)
|
||||
if result.Error != nil {
|
||||
|
||||
Reference in New Issue
Block a user