api管理测试完成,修复casbin的API更新随动map[string]string改为map[string]interface{}
This commit is contained in:
@@ -15,13 +15,10 @@ import (
|
||||
// @return error
|
||||
|
||||
func CreateApi(api model.SysApi) (err error) {
|
||||
findOne := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).Error
|
||||
if findOne == nil {
|
||||
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound){
|
||||
return errors.New("存在相同api")
|
||||
} else {
|
||||
err = global.GVA_DB.Create(&api).Error
|
||||
}
|
||||
return err
|
||||
return global.GVA_DB.Create(&api).Error
|
||||
}
|
||||
|
||||
// @title DeleteApi
|
||||
@@ -125,8 +122,7 @@ func UpdateApi(api model.SysApi) (err error) {
|
||||
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
|
||||
|
||||
if oldA.Path != api.Path || oldA.Method != api.Method {
|
||||
flag := errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).Error, gorm.ErrRecordNotFound)
|
||||
if !flag {
|
||||
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("存在相同api路径")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,7 @@ func AddCasbin(cm model.CasbinModel) bool {
|
||||
// @return error
|
||||
|
||||
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
|
||||
var cs []model.CasbinModel
|
||||
err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Find(&cs).Updates(map[string]string{
|
||||
err := global.GVA_DB.Table("casbin_rule").Model(&model.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{
|
||||
"v1": newPath,
|
||||
"v2": newMethod,
|
||||
}).Error
|
||||
|
||||
Reference in New Issue
Block a user