feat: RBAC 基本完成
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
"sundynix-go/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MenuApi struct {
|
||||
}
|
||||
|
||||
func (m *MenuApi) SaveMenu(c *gin.Context) {
|
||||
var menu system.Menu
|
||||
err := c.ShouldBindJSON(&menu)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = menuService.SaveMenu(menu); err != nil {
|
||||
global.Logger.Error("保存菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
} else {
|
||||
response.OkWithMsg("保存菜单成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MenuApi) UpdateMenu(c *gin.Context) {
|
||||
var menu system.Menu
|
||||
err := c.ShouldBindJSON(&menu)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = menuService.UpdateMenu(&menu); err != nil {
|
||||
global.Logger.Error("更新菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
} else {
|
||||
response.OkWithMsg("更新菜单成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MenuApi) DeleteMenu(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
err := menuService.DeleteMenu(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除菜单成功!", c)
|
||||
}
|
||||
|
||||
func (m *MenuApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
menu, err := menuService.GetMenuById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取菜单详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(menu, c)
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetAllMenuTree(c *gin.Context) {
|
||||
var param systemReq.GetMenuTree
|
||||
err := c.ShouldBindJSON(¶m)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
menus, err := menuService.GetAllMenuTree(param.Category, param.ParentId)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取菜单树结构失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(menus, c)
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetUserMenuTree(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (m *MenuApi) Route(c *gin.Context) {
|
||||
userId := utils.GetUserId(c)
|
||||
routes, err := menuService.GetUserRoutes(userId)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(routes, c)
|
||||
}
|
||||
Reference in New Issue
Block a user