feat:完善信息
This commit is contained in:
264
app/manage/api/role.go
Normal file
264
app/manage/api/role.go
Normal file
@ -0,0 +1,264 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/manage/controller/role"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Role struct{}
|
||||
|
||||
func (a *Role) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Select(c *gin.Context) {
|
||||
data, err := role.NewInstance()(getSession()(c).(*service.Session)).Select()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Add(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark" binding:"required"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewInstance()(getSession()(c).(*service.Session)).Data(0, form.Name, form.Remark, form.Sort)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark" binding:"required"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewInstance()(getSession()(c).(*service.Session)).Data(form.ID, form.Name, form.Remark, form.Sort)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Status(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/menu 菜单信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleMenu
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Role) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewMenu()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/menu/bind 菜单绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleMenuBind
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
* @apiParam {Array.Number} menu_ids 菜单ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Role) MenuBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewMenu()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/auth 权限信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleAuth
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind_title 权限类型名称
|
||||
* @apiSuccess (200) {String} data.kind 权限类型
|
||||
* @apiSuccess (200) {String} data.name 权限名称
|
||||
* @apiSuccess (200) {String} data.auth 权限信息
|
||||
* @apiSuccess (200) {Bool} data.checked 选中状态
|
||||
* @apiSuccess (200) {String} data.remark 备注信息
|
||||
* @apiSuccess (200) {Array} data.children 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* {
|
||||
* "id": 1,
|
||||
* "kind": 1,
|
||||
* "name": "测试",
|
||||
* "auth": "",
|
||||
* "checked": false,
|
||||
* "remark": "",
|
||||
* "created_at": "2021-09-15T13:59:35+08:00",
|
||||
* "updated_at": "2021-09-15T13:59:35+08:00",
|
||||
* "kind_title": "模块",
|
||||
* "children": []
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (a *Role) Auth(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewAuth()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/auth/bind 权限绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleAuthBind
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
* @apiParam {Array.Number} auth_ids 权限ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Role) AuthBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewAuth()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
Reference in New Issue
Block a user