feat: 完成"角色所有"和"角色详情"接口

This commit is contained in:
geeknonerd
2023-01-02 20:47:27 +08:00
parent d961688c89
commit 9501f89c75
4 changed files with 39 additions and 0 deletions

View File

@@ -25,7 +25,9 @@ func init() {
Group.AddPOST("/admin/upInfo", adminUpInfo, middleware.RecordLog("管理员更新"))
Group.AddPOST("/admin/del", adminDel, middleware.RecordLog("管理员删除"))
Group.AddPOST("/admin/disable", adminDisable, middleware.RecordLog("管理员状态切换"))
Group.AddGET("/role/all", roleAll)
Group.AddGET("/role/list", roleList, middleware.RecordLog("角色列表"))
Group.AddGET("/role/detail", roleDetail, middleware.RecordLog("角色详情"))
Group.AddGET("/menu/route", menuRoute)
Group.AddGET("/menu/list", menuList)
}
@@ -108,6 +110,11 @@ func adminDisable(c *gin.Context) {
response.Ok(c)
}
//roleAll 角色所有
func roleAll(c *gin.Context) {
response.OkWithData(c, system.SystemAuthRoleService.All())
}
//roleList 角色列表
func roleList(c *gin.Context) {
var page request.PageReq
@@ -115,6 +122,13 @@ func roleList(c *gin.Context) {
response.OkWithData(c, system.SystemAuthRoleService.List(page))
}
//roleDetail 角色详情
func roleDetail(c *gin.Context) {
var detailReq req.SystemAuthRoleDetailReq
utils.VerifyUtil.VerifyQuery(c, &detailReq)
response.OkWithData(c, system.SystemAuthRoleService.Detail(detailReq.ID))
}
//menuRoute 菜单路由
func menuRoute(c *gin.Context) {
adminId := config.AdminConfig.GetAdminId(c)

View File

@@ -69,3 +69,8 @@ type SystemAuthAdminDelReq struct {
type SystemAuthAdminDisableReq struct {
ID uint `form:"id" binding:"required,gt=0"` // 主键
}
//SystemAuthRoleDetailReq 角色详情参数
type SystemAuthRoleDetailReq struct {
ID uint `form:"id" binding:"required,gt=0"` // 主键
}

View File

@@ -47,6 +47,14 @@ type SystemAuthAdminSelfResp struct {
Permissions []string `json:"permissions" structs:"permissions"` // 权限集合: [[*]=>所有权限, ['article:add']=>部分权限]
}
//SystemAuthRoleSimpleResp 系统角色返回简单信息
type SystemAuthRoleSimpleResp struct {
ID uint `json:"id" structs:"id"` // 主键
Name string `json:"name" structs:"name"` // 角色名称
CreateTime core.TsTime `json:"createTime" structs:"createTime"` // 创建时间
UpdateTime core.TsTime `json:"updateTime" structs:"updateTime"` // 更新时间
}
//SystemAuthRoleResp 系统角色返回信息
type SystemAuthRoleResp struct {
ID uint `json:"id" structs:"id"` // 主键

View File

@@ -15,6 +15,18 @@ var SystemAuthRoleService = systemAuthRoleService{}
//systemAuthRoleService 系统角色服务实现类
type systemAuthRoleService struct{}
//All 角色所有
func (roleSrv systemAuthRoleService) All() (res []resp.SystemAuthRoleSimpleResp) {
var roles []system.SystemAuthRole
err := core.DB.Order("sort desc, id desc").Find(&roles).Error
if err != nil {
core.Logger.Errorf("All Find err: err=[%+v]", err)
panic(response.SystemError)
}
response.Copy(&res, roles)
return
}
//List 根据角色ID获取菜单ID
func (roleSrv systemAuthRoleService) List(page request.PageReq) response.PageResp {
var res response.PageResp