Skip to content

Commit

Permalink
fix: 更新api路径时使用binary区分大小写进行查询 (#1645)
Browse files Browse the repository at this point in the history
* fix: 更新api路径时使用`binary`区分大小写进行查询

* fix: 修改相同api路径判断逻辑
  • Loading branch information
G-XD committed Feb 4, 2024
1 parent 06701cc commit e32dbb5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions server/service/system/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ func (apiService *ApiService) UpdateApi(api system.SysApi) (err error) {
var oldA system.SysApi
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
if oldA.Path != api.Path || oldA.Method != api.Method {
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&system.SysApi{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同api路径")
var duplicateApi system.SysApi
if err := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&duplicateApi).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
} else {
if duplicateApi.ID != api.ID {
return errors.New("存在相同api路径")
}
}
}
if err != nil {
Expand Down

0 comments on commit e32dbb5

Please sign in to comment.