diff --git a/server/api/v1/sys_api.go b/server/api/v1/sys_api.go index 37c769c4..4b04a20d 100644 --- a/server/api/v1/sys_api.go +++ b/server/api/v1/sys_api.go @@ -111,12 +111,9 @@ func GetApiList(c *gin.Context) { func GetApiById(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) - ApiVerify := utils.Rules{ - "Id": {utils.NotEmpty()}, - } - ApiVerifyErr := utils.Verify(idInfo, ApiVerify) - if ApiVerifyErr != nil { - response.FailWithMessage(ApiVerifyErr.Error(), c) + IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"]) + if IdVerifyErr != nil { + response.FailWithMessage(IdVerifyErr.Error(), c) return } err, api := service.GetApiById(idInfo.Id) diff --git a/server/api/v1/sys_authority.go b/server/api/v1/sys_authority.go index 2d6a2b8c..10f91c21 100644 --- a/server/api/v1/sys_authority.go +++ b/server/api/v1/sys_authority.go @@ -88,12 +88,9 @@ func CopyAuthority(c *gin.Context) { func DeleteAuthority(c *gin.Context) { var a model.SysAuthority _ = c.ShouldBindJSON(&a) - AuthorityVerify := utils.Rules{ - "AuthorityId": {utils.NotEmpty()}, - } - AuthorityVerifyErr := utils.Verify(a, AuthorityVerify) - if AuthorityVerifyErr != nil { - response.FailWithMessage(AuthorityVerifyErr.Error(), c) + AuthorityIdVerifyErr := utils.Verify(a, utils.CustomizeMap["AuthorityIdVerify"]) + if AuthorityIdVerifyErr != nil { + response.FailWithMessage(AuthorityIdVerifyErr.Error(), c) return } //删除角色之前需要判断是否有用户正在使用此角色 @@ -174,12 +171,9 @@ func GetAuthorityList(c *gin.Context) { func SetDataAuthority(c *gin.Context) { var auth model.SysAuthority _ = c.ShouldBindJSON(&auth) - AuthorityVerify := utils.Rules{ - "AuthorityId": {utils.NotEmpty()}, - } - AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify) - if AuthorityVerifyErr != nil { - response.FailWithMessage(AuthorityVerifyErr.Error(), c) + AuthorityIdVerifyErr := utils.Verify(auth, utils.CustomizeMap["AuthorityIdVerify"]) + if AuthorityIdVerifyErr != nil { + response.FailWithMessage(AuthorityIdVerifyErr.Error(), c) return } err := service.SetDataAuthority(auth) diff --git a/server/api/v1/sys_casbin.go b/server/api/v1/sys_casbin.go index f3dd14ae..abe0c65e 100644 --- a/server/api/v1/sys_casbin.go +++ b/server/api/v1/sys_casbin.go @@ -21,12 +21,9 @@ import ( func UpdateCasbin(c *gin.Context) { var cmr request.CasbinInReceive _ = c.ShouldBindJSON(&cmr) - CasbinVerify := utils.Rules{ - "AuthorityId": {utils.NotEmpty()}, - } - WKVerifyErr := utils.Verify(cmr, CasbinVerify) - if WKVerifyErr!=nil { - response.FailWithMessage(WKVerifyErr.Error(), c) + AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"]) + if AuthorityIdVerifyErr != nil { + response.FailWithMessage(AuthorityIdVerifyErr.Error(), c) return } err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos) @@ -48,12 +45,9 @@ func UpdateCasbin(c *gin.Context) { func GetPolicyPathByAuthorityId(c *gin.Context) { var cmr request.CasbinInReceive _ = c.ShouldBindJSON(&cmr) - CasbinVerify := utils.Rules{ - "AuthorityId": {utils.NotEmpty()}, - } - WKVerifyErr := utils.Verify(cmr, CasbinVerify) - if WKVerifyErr!=nil { - response.FailWithMessage(WKVerifyErr.Error(), c) + AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"]) + if AuthorityIdVerifyErr != nil { + response.FailWithMessage(AuthorityIdVerifyErr.Error(), c) return } paths := service.GetPolicyPathByAuthorityId(cmr.AuthorityId) diff --git a/server/api/v1/sys_menu.go b/server/api/v1/sys_menu.go index f551c966..fa1da790 100644 --- a/server/api/v1/sys_menu.go +++ b/server/api/v1/sys_menu.go @@ -178,12 +178,9 @@ func GetMenuAuthority(c *gin.Context) { func DeleteBaseMenu(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) - MenuVerify := utils.Rules{ - "Id": {"notEmpty"}, - } - MenuVerifyErr := utils.Verify(idInfo, MenuVerify) - if MenuVerifyErr != nil { - response.FailWithMessage(MenuVerifyErr.Error(), c) + IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"]) + if IdVerifyErr != nil { + response.FailWithMessage(IdVerifyErr.Error(), c) return } err := service.DeleteBaseMenu(idInfo.Id) diff --git a/server/api/v1/sys_user.go b/server/api/v1/sys_user.go index 64b954b4..9535248d 100644 --- a/server/api/v1/sys_user.go +++ b/server/api/v1/sys_user.go @@ -282,12 +282,9 @@ func SetUserAuthority(c *gin.Context) { func DeleteUser(c *gin.Context) { var reqId request.GetById _ = c.ShouldBindJSON(&reqId) - UserVerify := utils.Rules{ - "Id": {utils.NotEmpty()}, - } - UserVerifyErr := utils.Verify(reqId, UserVerify) - if UserVerifyErr != nil { - response.FailWithMessage(UserVerifyErr.Error(), c) + IdVerifyErr := utils.Verify(reqId, utils.CustomizeMap["IdVerify"]) + if IdVerifyErr != nil { + response.FailWithMessage(IdVerifyErr.Error(), c) return } err := service.DeleteUser(reqId.Id) diff --git a/server/initialize/validator.go b/server/initialize/validator.go index 97a89240..2fdc6523 100644 --- a/server/initialize/validator.go +++ b/server/initialize/validator.go @@ -9,4 +9,14 @@ func init() { "PageSize": {utils.NotEmpty()}, }, ) + _ = utils.RegisterRule("IdVerify", + utils.Rules{ + "Id": {utils.NotEmpty()}, + }, + ) + _ = utils.RegisterRule("AuthorityIdVerify", + utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + }, + ) }