feat: RBAC 基本完成
This commit is contained in:
+26
-14
@@ -1,13 +1,14 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"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"
|
||||
)
|
||||
|
||||
type RoleApi struct {
|
||||
@@ -17,10 +18,10 @@ func (a *RoleApi) SaveRole(context *gin.Context) {
|
||||
var role system.Role
|
||||
err := context.ShouldBindJSON(&role)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
response.FailWithMsg("参数错误"+err.Error(), context)
|
||||
return
|
||||
}
|
||||
err = RoleService.SaveRole(role)
|
||||
err = roleService.SaveRole(role)
|
||||
if err != nil {
|
||||
global.Logger.Error("保存角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
@@ -36,7 +37,7 @@ func (a *RoleApi) UpdateRole(context *gin.Context) {
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
err = RoleService.UpdateRole(role)
|
||||
err = roleService.UpdateRole(role)
|
||||
if err != nil {
|
||||
global.Logger.Error("更新角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
@@ -52,7 +53,7 @@ func (a *RoleApi) GetRoleList(c *gin.Context) {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := RoleService.GetRoleList(pageInfo)
|
||||
list, total, err := roleService.GetRoleList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取角色列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
@@ -72,7 +73,7 @@ func (a *RoleApi) Delete(context *gin.Context) {
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
err = RoleService.DeleteRoleByIds(ids)
|
||||
err = roleService.DeleteRoleByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
@@ -82,13 +83,8 @@ func (a *RoleApi) Delete(context *gin.Context) {
|
||||
}
|
||||
|
||||
func (a *RoleApi) Detail(context *gin.Context) {
|
||||
var idInfo request.GetById
|
||||
err := context.ShouldBindJSON(&idInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
role, err := RoleService.GetRoleById(idInfo.ID)
|
||||
id := context.Query("id")
|
||||
role, err := roleService.GetRoleById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取角色详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
@@ -96,3 +92,19 @@ func (a *RoleApi) Detail(context *gin.Context) {
|
||||
}
|
||||
response.OkWithData(role, context)
|
||||
}
|
||||
|
||||
func (a *RoleApi) GrantMenu(c *gin.Context) {
|
||||
var grantMenu systemreq.GrantMenu
|
||||
err := c.ShouldBindJSON(&grantMenu)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = roleService.GrantMenu(grantMenu.RoleId, grantMenu.MenuIds)
|
||||
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