From e32dbb5125888ffe5ef937ebbbcdcf1cdde868a9 Mon Sep 17 00:00:00 2001 From: G-XD Date: Sun, 4 Feb 2024 11:35:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0api=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=97=B6=E4=BD=BF=E7=94=A8`binary`=E5=8C=BA=E5=88=86=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=86=99=E8=BF=9B=E8=A1=8C=E6=9F=A5=E8=AF=A2=20(#1645?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 更新api路径时使用`binary`区分大小写进行查询 * fix: 修改相同api路径判断逻辑 --- server/service/system/sys_api.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/service/system/sys_api.go b/server/service/system/sys_api.go index 5c0d8935..0226bd92 100644 --- a/server/service/system/sys_api.go +++ b/server/service/system/sys_api.go @@ -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 {