From 4907706b4943d1012cd5015285dd4c725c2f877b Mon Sep 17 00:00:00 2001 From: SliverHorn <503551462@qq.com> Date: Wed, 26 Aug 2020 11:23:40 +0800 Subject: [PATCH] =?UTF-8?q?api=E7=AE=A1=E7=90=86=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=AE=8C=E6=88=90,=E4=BF=AE=E5=A4=8Dcasbin=E7=9A=84API?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9A=8F=E5=8A=A8map[string]string=E6=94=B9?= =?UTF-8?q?=E4=B8=BAmap[string]interface{}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13\350\257\225\346\226\207\346\241\243.md" | 136 +++++++++--------- server/service/sys_api.go | 10 +- server/service/sys_casbin.go | 3 +- 3 files changed, 72 insertions(+), 77 deletions(-) diff --git "a/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" "b/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" index 7f16aac4..2c3e7d5a 100644 --- "a/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" +++ "b/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" @@ -1,68 +1,68 @@ -| 路由path | 路由描述 | 测试情况 | -| ------------------------------------------------- | ----------------------- | :------: | -| /base/login | 用户登录 | √ | -| /base/register | 用户注册 | | -| /api/createApi | 创建api | | -| /api/getApiList | 获取api详细信息 | | -| /api/deleteApi | 删除Api | | -| /api/updateApi | 更新Api | | -| /api/getAllApis | 获取所有api | | -| /authority/createAuthority | 创建角色 | √ | -| /authority/createAuthority | 创建子角色 | √ | -| /authority/deleteAuthority | 删除角色 | √ | -| /authority/getAuthorityList | 获取角色列表 | √ | -| /menu/getMenu | 获取菜单树 | | -| /menu/getMenuList | 分页获取基础menu列表 | | -| /menu/addBaseMenu | 新增菜单 | | -| /menu/getBaseMenuTree | 获取用户动态路由 | | -| /menu/addMenuAuthority | 增加menu和角色关联关系 | | -| /menu/getMenuAuthority | 获取指定角色menu | | -| /menu/deleteBaseMenu | 删除菜单 | | -| /menu/updateBaseMenu | 更新菜单 | | -| /menu/getBaseMenuById | 根据id获取菜单 | | -| /user/changePassword | 修改密码 | | -| /user/uploadHeaderImg | 上传头像 | | -| /user/getInfoList | 分页获取用户列表 | | -| /user/getUserList | 获取用户列表 | | -| /user/setUserAuthority | 修改用户角色 | | -| /fileUploadAndDownload/upload | 文件上传示例 | | -| /fileUploadAndDownload/getFileList | 获取上传文件列表 | | -| /casbin/updateCasbin | 更改角色api权限 | | -| /casbin/getPolicyPathByAuthorityId | 获取权限列表 | | -| /fileUploadAndDownload/deleteFile | 删除文件 | | -| /jwt/jsonInBlacklist | jwt加入黑名单 | | -| /authority/setDataAuthority | 设置角色资源权限 | | -| /system/getSystemConfig | 获取配置文件内容 | | -| /system/setSystemConfig | 设置配置文件内容 | | -| /customer/customer | 创建客户 | | -| /customer/customer | 更新客户 | | -| /customer/customer | 删除客户 | | -| /customer/customer | 获取单一客户 | | -| /customer/customerList | 获取客户列表 | | -| /casbin/casbinTest/:pathParam | RESTFUL模式测试 | | -| /autoCode/createTemp | 自动化代码 | | -| /authority/updateAuthority | 更新角色信息 | | -| /authority/copyAuthority | 拷贝角色 | | -| /user/deleteUser | 删除用户 | | -| /sysDictionaryDetail/createSysDictionaryDetail | 新增字典内容 | | -| /sysDictionaryDetail/deleteSysDictionaryDetail | 新增字典内容 | | -| /sysDictionaryDetail/updateSysDictionaryDetail | 新增字典内容 | | -| /sysDictionaryDetail/findSysDictionaryDetail | 根据ID获取字典内容 | | -| /sysDictionaryDetail/getSysDictionaryDetailList | 获取字典内容列表 | | -| /sysDictionary/createSysDictionary | 新增字典 | | -| /sysDictionary/deleteSysDictionary | 删除字典 | | -| /sysDictionary/updateSysDictionary | 更新字典 | | -| /sysDictionary/findSysDictionary | 根据ID获取字典 | | -| /sysDictionary/getSysDictionaryList | 获取字典列表 | | -| /sysOperationRecord/createSysOperationRecord | 新增操作记录 | | -| /sysOperationRecord/deleteSysOperationRecord | 删除操作记录 | | -| /sysOperationRecord/updateSysOperationRecord | 更新操作记录 | | -| /sysOperationRecord/findSysOperationRecord | 根据ID获取操作记录 | | -| /sysOperationRecord/getSysOperationRecordList | 获取操作记录列表 | | -| /autoCode/getTables | 获取数据库表 | √ | -| /autoCode/getDB | 获取所有数据库 | √ | -| /autoCode/getColume | 获取所选table的所有字段 | √ | -| /sysOperationRecord/deleteSysOperationRecordByIds | 批量删除操作历史 | | -| /simpleUploader/upload | 插件版分片上传 | | -| /simpleUploader/checkFileMd5 | 文件完整度验证 | | -| /simpleUploader/mergeFileMd5 | 上传完成合并文件 | | +| 路由path | 路由描述 | 测试情况 | 备注 | +| ------------------------------------------------- | ----------------------- | :------: | ---------- | +| /base/login | 用户登录 | √ | SliverHorn | +| /base/register | 用户注册 | | | +| /api/createApi | 创建api | √ | SliverHorn | +| /api/getApiList | 获取api详细信息 | √ | SliverHorn | +| /api/deleteApi | 删除Api | √ | SliverHorn | +| /api/updateApi | 更新Api | √ | SliverHorn | +| /api/getAllApis | 获取所有api | √ | SliverHorn | +| /authority/createAuthority | 创建角色 | √ | SliverHorn | +| /authority/createAuthority | 创建子角色 | √ | SliverHorn | +| /authority/deleteAuthority | 删除角色 | √ | SliverHorn | +| /authority/getAuthorityList | 获取角色列表 | √ | SliverHorn | +| /menu/getMenu | 获取菜单树 | √ | SliverHorn | +| /menu/getMenuList | 分页获取基础menu列表 | | | +| /menu/addBaseMenu | 新增菜单 | | | +| /menu/getBaseMenuTree | 获取用户动态路由 | | | +| /menu/addMenuAuthority | 增加menu和角色关联关系 | | | +| /menu/getMenuAuthority | 获取指定角色menu | | | +| /menu/deleteBaseMenu | 删除菜单 | | | +| /menu/updateBaseMenu | 更新菜单 | | | +| /menu/getBaseMenuById | 根据id获取菜单 | | | +| /user/changePassword | 修改密码 | | | +| /user/uploadHeaderImg | 上传头像 | | | +| /user/getInfoList | 分页获取用户列表 | | | +| /user/getUserList | 获取用户列表 | | | +| /user/setUserAuthority | 修改用户角色 | | | +| /fileUploadAndDownload/upload | 文件上传示例 | | | +| /fileUploadAndDownload/getFileList | 获取上传文件列表 | | | +| /casbin/updateCasbin | 更改角色api权限 | | | +| /casbin/getPolicyPathByAuthorityId | 获取权限列表 | | | +| /fileUploadAndDownload/deleteFile | 删除文件 | | | +| /jwt/jsonInBlacklist | jwt加入黑名单 | | | +| /authority/setDataAuthority | 设置角色资源权限 | | | +| /system/getSystemConfig | 获取配置文件内容 | | | +| /system/setSystemConfig | 设置配置文件内容 | | | +| /customer/customer | 创建客户 | | | +| /customer/customer | 更新客户 | | | +| /customer/customer | 删除客户 | | | +| /customer/customer | 获取单一客户 | | | +| /customer/customerList | 获取客户列表 | | | +| /casbin/casbinTest/:pathParam | RESTFUL模式测试 | | | +| /autoCode/createTemp | 自动化代码 | | | +| /authority/updateAuthority | 更新角色信息 | | | +| /authority/copyAuthority | 拷贝角色 | | | +| /user/deleteUser | 删除用户 | | | +| /sysDictionaryDetail/createSysDictionaryDetail | 新增字典内容 | | | +| /sysDictionaryDetail/deleteSysDictionaryDetail | 新增字典内容 | | | +| /sysDictionaryDetail/updateSysDictionaryDetail | 新增字典内容 | | | +| /sysDictionaryDetail/findSysDictionaryDetail | 根据ID获取字典内容 | | | +| /sysDictionaryDetail/getSysDictionaryDetailList | 获取字典内容列表 | | | +| /sysDictionary/createSysDictionary | 新增字典 | | | +| /sysDictionary/deleteSysDictionary | 删除字典 | | | +| /sysDictionary/updateSysDictionary | 更新字典 | | | +| /sysDictionary/findSysDictionary | 根据ID获取字典 | | | +| /sysDictionary/getSysDictionaryList | 获取字典列表 | | | +| /sysOperationRecord/createSysOperationRecord | 新增操作记录 | | | +| /sysOperationRecord/deleteSysOperationRecord | 删除操作记录 | | | +| /sysOperationRecord/updateSysOperationRecord | 更新操作记录 | | | +| /sysOperationRecord/findSysOperationRecord | 根据ID获取操作记录 | | | +| /sysOperationRecord/getSysOperationRecordList | 获取操作记录列表 | | | +| /autoCode/getTables | 获取数据库表 | √ | | +| /autoCode/getDB | 获取所有数据库 | √ | | +| /autoCode/getColume | 获取所选table的所有字段 | √ | | +| /sysOperationRecord/deleteSysOperationRecordByIds | 批量删除操作历史 | | | +| /simpleUploader/upload | 插件版分片上传 | | | +| /simpleUploader/checkFileMd5 | 文件完整度验证 | | | +| /simpleUploader/mergeFileMd5 | 上传完成合并文件 | | | diff --git a/server/service/sys_api.go b/server/service/sys_api.go index 68bdab6e..f8715034 100644 --- a/server/service/sys_api.go +++ b/server/service/sys_api.go @@ -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路径") } } diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index 790ce6fd..19c7721d 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -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 -- GitLab