feat: Role 增删改查

This commit is contained in:
Blizzard
2025-05-11 22:54:11 +08:00
parent ab51ba91bc
commit 2ec091bf59
9 changed files with 194 additions and 0 deletions
+98
View File
@@ -0,0 +1,98 @@
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"
)
type RoleApi struct {
}
func (a *RoleApi) SaveRole(context *gin.Context) {
var role system.Role
err := context.ShouldBindJSON(&role)
if err != nil {
response.FailWithMsg(err.Error(), context)
return
}
err = RoleService.SaveRole(role)
if err != nil {
global.Logger.Error("保存角色失败!", zap.Error(err))
response.FailWithMsg(err.Error(), context)
return
}
response.OkWithMsg("保存角色成功!", context)
}
func (a *RoleApi) UpdateRole(context *gin.Context) {
var role system.Role
err := context.ShouldBindJSON(&role)
if err != nil {
response.FailWithMsg(err.Error(), context)
return
}
err = RoleService.UpdateRole(role)
if err != nil {
global.Logger.Error("更新角色失败!", zap.Error(err))
response.FailWithMsg(err.Error(), context)
return
}
response.OkWithMsg("更新角色成功!", context)
}
func (a *RoleApi) GetRoleList(c *gin.Context) {
var pageInfo systemreq.GetRoleList
err := c.ShouldBindJSON(&pageInfo)
if err != nil {
response.FailWithMsg(err.Error(), c)
return
}
list, total, err := RoleService.GetRoleList(pageInfo)
if err != nil {
global.Logger.Error("获取角色列表失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
}
response.OkWithData(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Current,
PageSize: pageInfo.PageSize,
}, c)
}
func (a *RoleApi) Delete(context *gin.Context) {
var ids request.IdsReq
err := context.ShouldBindJSON(&ids)
if err != nil {
response.FailWithMsg(err.Error(), context)
return
}
err = RoleService.DeleteRoleByIds(ids)
if err != nil {
global.Logger.Error("删除角色失败!", zap.Error(err))
response.FailWithMsg(err.Error(), context)
return
}
response.OkWithMsg("删除角色成功!", 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)
if err != nil {
global.Logger.Error("获取角色详情失败!", zap.Error(err))
response.FailWithMsg(err.Error(), context)
return
}
response.OkWithData(role, context)
}