feat: RBAC 基本完成
This commit is contained in:
@@ -1,16 +1,49 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/response"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
)
|
||||
|
||||
type UserApi struct {
|
||||
}
|
||||
|
||||
func (u *UserApi) SaveUser(c *gin.Context) {
|
||||
var user system.User
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = userService.SaveUser(user); err != nil {
|
||||
global.Logger.Error("保存用户失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMsg("保存用户成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserApi) UpdateUser(c *gin.Context) {
|
||||
var user system.User
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = userService.UpdateUser(&user); err != nil {
|
||||
global.Logger.Error("更新用户失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMsg("更新用户成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserApi) GetUserList(c *gin.Context) {
|
||||
var pageInfo systemReq.GetUserList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
@@ -18,7 +51,7 @@ func (u *UserApi) GetUserList(c *gin.Context) {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := UserService.GetUserList(pageInfo)
|
||||
list, total, err := userService.GetUserList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
@@ -31,3 +64,62 @@ func (u *UserApi) GetUserList(c *gin.Context) {
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
func (u *UserApi) Delete(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = userService.DeleteUserByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除用户失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除用户成功!", c)
|
||||
}
|
||||
|
||||
func (u *UserApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
user, err := userService.GetUserById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(user, c)
|
||||
}
|
||||
|
||||
func (u *UserApi) ChangePassword(c *gin.Context) {
|
||||
var changePwd systemReq.ChangePwd
|
||||
err := c.ShouldBindJSON(&changePwd)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = userService.ChangePassword(changePwd.Id, changePwd.NewPwd)
|
||||
if err != nil {
|
||||
global.Logger.Error("修改密码失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("修改密码成功", c)
|
||||
}
|
||||
|
||||
func (u *UserApi) GrantRole(c *gin.Context) {
|
||||
var grantRole systemReq.GrantRole
|
||||
err := c.ShouldBindJSON(&grantRole)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = roleService.GrantRole(grantRole.UserId, grantRole.RoleIds)
|
||||
if err != nil {
|
||||
global.Logger.Error("授权角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("授权角色成功!", c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user