用户接口调整

This commit is contained in:
TsMask
2023-08-30 16:03:03 +08:00
parent 81747291bf
commit b6431d514e

View File

@@ -29,7 +29,7 @@ func Routers() []services.RouterItem {
rs := [...]services.RouterItem{ rs := [...]services.RouterItem{
{ {
Method: "GET", Method: "GET",
Pattern: "/userManage/{apiVersion}/list", Pattern: "/users",
Handler: apis.List, Handler: apis.List,
Middleware: midware.Authorize(map[string][]string{ Middleware: midware.Authorize(map[string][]string{
"hasPerms": {"system:user:list"}, "hasPerms": {"system:user:list"},
@@ -37,7 +37,7 @@ func Routers() []services.RouterItem {
}, },
{ {
Method: "GET", Method: "GET",
Pattern: "/userManage/{apiVersion}/info/{userId}", Pattern: "/user/{userId}",
Handler: apis.Info, Handler: apis.Info,
Middleware: midware.Authorize(map[string][]string{ Middleware: midware.Authorize(map[string][]string{
"hasPerms": {"system:user:query"}, "hasPerms": {"system:user:query"},
@@ -45,7 +45,7 @@ func Routers() []services.RouterItem {
}, },
{ {
Method: "POST", Method: "POST",
Pattern: "/userManage/{apiVersion}/add", Pattern: "/user",
Handler: apis.Add, Handler: apis.Add,
Middleware: midware.Authorize(map[string][]string{ Middleware: midware.Authorize(map[string][]string{
"hasPerms": {"system:user:add"}, "hasPerms": {"system:user:add"},
@@ -53,7 +53,7 @@ func Routers() []services.RouterItem {
}, },
{ {
Method: "PUT", Method: "PUT",
Pattern: "/userManage/{apiVersion}/edit", Pattern: "/user",
Handler: apis.Edit, Handler: apis.Edit,
Middleware: midware.Authorize(map[string][]string{ Middleware: midware.Authorize(map[string][]string{
"hasPerms": {"system:user:edit"}, "hasPerms": {"system:user:edit"},
@@ -61,7 +61,7 @@ func Routers() []services.RouterItem {
}, },
{ {
Method: "DELETE", Method: "DELETE",
Pattern: "/userManage/{apiVersion}/del/{userIds}", Pattern: "/user/{userIds}",
Handler: apis.Remove, Handler: apis.Remove,
Middleware: midware.Authorize(map[string][]string{ Middleware: midware.Authorize(map[string][]string{
"hasPerms": {"system:user:edit"}, "hasPerms": {"system:user:edit"},
@@ -73,7 +73,7 @@ func Routers() []services.RouterItem {
// 生成两组前缀路由 // 生成两组前缀路由
rsPrefix := []services.RouterItem{} rsPrefix := []services.RouterItem{}
for _, v := range rs { for _, v := range rs {
path := v.Pattern path := "/userManage/{apiVersion}" + v.Pattern
// 固定前缀 // 固定前缀
v.Pattern = config.DefaultUriPrefix + path v.Pattern = config.DefaultUriPrefix + path
rsPrefix = append(rsPrefix, v) rsPrefix = append(rsPrefix, v)
@@ -139,7 +139,6 @@ func (s *SysUserApi) Info(w http.ResponseWriter, r *http.Request) {
ctx.JSON(w, 200, result.OkData(map[string]any{ ctx.JSON(w, 200, result.OkData(map[string]any{
"user": map[string]any{}, "user": map[string]any{},
"roleIds": []string{}, "roleIds": []string{},
"postIds": []string{},
"roles": roles, "roles": roles,
})) }))
return return
@@ -177,9 +176,9 @@ func (s *SysUserApi) Add(w http.ResponseWriter, r *http.Request) {
} }
// 检查用户登录账号是否唯一 // 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.Name, "") uniqueUserName := s.sysUserService.CheckUniqueUserName(body.AccountId, "")
if !uniqueUserName { if !uniqueUserName {
msg := fmt.Sprintf("新增用户【%s】失败登录账号已存在", body.Name) msg := fmt.Sprintf("新增用户【%s】失败登录账号已存在", body.AccountId)
ctx.JSON(w, 200, result.ErrMsg(msg)) ctx.JSON(w, 200, result.ErrMsg(msg))
return return
} }
@@ -204,10 +203,10 @@ func (s *SysUserApi) Edit(w http.ResponseWriter, r *http.Request) {
} }
// 检查是否管理员用户 // 检查是否管理员用户
if conf.IsAdmin(body.Id) { // if conf.IsAdmin(body.Id) {
ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员用户")) // ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员用户"))
return // return
} // }
user := s.sysUserService.SelectUserById(body.Id) user := s.sysUserService.SelectUserById(body.Id)
if user.Id != body.Id { if user.Id != body.Id {
@@ -216,15 +215,15 @@ func (s *SysUserApi) Edit(w http.ResponseWriter, r *http.Request) {
} }
// 检查用户登录账号是否唯一 // 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.Name, body.Id) uniqueUserName := s.sysUserService.CheckUniqueUserName(body.AccountId, body.Id)
if !uniqueUserName { if !uniqueUserName {
msg := fmt.Sprintf("修改用户【%s】失败登录账号已存在", body.Name) msg := fmt.Sprintf("修改用户【%s】失败登录账号已存在", body.AccountId)
ctx.JSON(w, 200, result.ErrMsg(msg)) ctx.JSON(w, 200, result.ErrMsg(msg))
return return
} }
body.Name = "" // 忽略修改登录用户名称 body.AccountId = "" // 忽略修改登录用户名称
body.Password = "" // 忽略修改密码 // body.Password = "" // 忽略修改密码
rows := s.sysUserService.UpdateUserAndRolePost(body) rows := s.sysUserService.UpdateUserAndRolePost(body)
if rows > 0 { if rows > 0 {
ctx.JSON(w, 200, result.Ok(nil)) ctx.JSON(w, 200, result.Ok(nil))