feat:完善项目信息
This commit is contained in:
@ -2,32 +2,48 @@ package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Config struct{}
|
||||
|
||||
func (a *Config) List(c *gin.Context) {
|
||||
func (a *Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewConfig()().Config(form.Kind, form.Page, form.PageSize)
|
||||
APIResponse(err, data)
|
||||
api.APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (a *Config) Add(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
Value interface{} `json:"value" form:"value" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewConfig()().Add(form.Kind, form.Name, form.Key, form.Value)
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (a *Config) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
Params map[string]interface{} `json:"params" form:"params" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewConfig()().Form(form.Params)
|
||||
APIResponse(err)
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/api/admin/controller/department"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -10,58 +11,61 @@ import (
|
||||
type Department struct{}
|
||||
|
||||
type departmentForm struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Contact string `json:"contact" form:"contact_title"`
|
||||
ContactMobile string `json:"contact_mobile" form:"contact_mobile"`
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
func (a *Department) List(c *gin.Context) {
|
||||
data, err := controller.NewDepartment()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
func (a *Department) Index(c *gin.Context) {
|
||||
data, err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Select(c *gin.Context) {
|
||||
data, err := controller.NewDepartment()(getSession()(c).(*service.Session)).Select()
|
||||
APIResponse(err, data)(c)
|
||||
data, err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Select()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Add(c *gin.Context) {
|
||||
form := new(departmentForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Data(&controller.DepartmentParams{
|
||||
ParentID: form.ParentID, Title: form.Title, Name: form.Name, Mobile: form.Mobile, Remark: form.Remark,
|
||||
err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&department.InstanceParams{
|
||||
ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(), Contact: form.Contact, Name: form.Name,
|
||||
ContactMobile: form.ContactMobile, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
departmentForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Data(&controller.DepartmentParams{
|
||||
ID: form.ID, ParentID: form.ParentID, Title: form.Title, Name: form.Name, Mobile: form.Mobile, Remark: form.Remark,
|
||||
err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&department.InstanceParams{
|
||||
ID: form.Convert(), ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(), Contact: form.Contact,
|
||||
Name: form.Name, ContactMobile: form.ContactMobile, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
@ -13,78 +13,80 @@ type Menu struct{}
|
||||
type (
|
||||
// menuForm 菜单信息
|
||||
menuForm struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Link string `json:"link" form:"link"`
|
||||
Link string `json:"path" form:"path"`
|
||||
Component string `json:"component" form:"component"`
|
||||
Icon string `json:"icon" form:"icon"`
|
||||
Auth int `json:"auth" form:"auth"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
IsCache int `json:"is_cache" form:"is_cache"`
|
||||
Hidden int `json:"hidden" form:"hidden"`
|
||||
Status int `json:"status" form:"status"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @apiDefine Menu 菜单管理
|
||||
*/
|
||||
|
||||
func (a *Menu) List(c *gin.Context) {
|
||||
data, err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).List()
|
||||
data, err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Menu) Add(c *gin.Context) {
|
||||
form := new(menuForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&menu.InstanceParams{
|
||||
ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(),
|
||||
Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
IsCache: form.IsCache, IsHidden: form.Hidden,
|
||||
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Menu) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
menuForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&menu.InstanceParams{
|
||||
ID: form.ID, ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
ID: form.Convert(), ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(), Name: form.Name,
|
||||
Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
Icon: form.Icon, Auth: form.Auth, IsCache: form.IsCache, IsHidden: form.Hidden,
|
||||
Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Menu) Status(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Status(form.ID, form.Status)
|
||||
APIResponse(err)(c)
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Status(form.Convert(), form.Status)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Menu) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
@ -1,132 +1,89 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
role2 "SciencesServer/app/api/admin/controller/role"
|
||||
"SciencesServer/app/api/admin/controller/role"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Role struct{}
|
||||
|
||||
func (a *Role) List(c *gin.Context) {
|
||||
func (*Role) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
pageForm
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role2.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := role.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Name, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Select(c *gin.Context) {
|
||||
data, err := role2.NewInstance()(getSession()(c).(*service.Session)).Select()
|
||||
APIResponse(err, data)(c)
|
||||
func (*Role) Select(c *gin.Context) {
|
||||
data, err := role.NewInstance()(api.GetSession()(c).(*session.Admin)).Select()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Add(c *gin.Context) {
|
||||
func (*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)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Data(0, form.Name, form.Remark, form.Sort)
|
||||
APIResponse(err)(c)
|
||||
err := role.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(0, form.Name, form.Remark, form.Sort)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Edit(c *gin.Context) {
|
||||
func (*Role) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
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)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Data(form.ID, form.Name, form.Remark, form.Sort)
|
||||
APIResponse(err)(c)
|
||||
err := role.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(form.Convert(), form.Name, form.Remark, form.Sort)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Status(c *gin.Context) {
|
||||
func (*Role) Status(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
|
||||
APIResponse(err)(c)
|
||||
err := role.NewInstance()(api.GetSession()(c).(*session.Admin)).Status(form.Convert(), form.Status)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
func (*Role) Delete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
err := role.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.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) {
|
||||
func (*Role) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
@ -134,33 +91,11 @@ func (a *Role) Menu(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role2.NewMenu()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
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) {
|
||||
func (*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"`
|
||||
@ -169,54 +104,11 @@ func (a *Role) MenuBind(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewMenu()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
|
||||
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) {
|
||||
func (*Role) Auth(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
@ -224,33 +116,11 @@ func (a *Role) Auth(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role2.NewAuth()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
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) {
|
||||
func (*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"`
|
||||
@ -259,6 +129,6 @@ func (a *Role) AuthBind(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewAuth()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
|
||||
err := role.NewAuth()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
@ -12,20 +12,32 @@ import (
|
||||
type User struct{}
|
||||
|
||||
type userForm struct {
|
||||
Account string `json:"account" form:"account" binding:"required"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Gender int `json:"gender" form:"gender" binding:"required"`
|
||||
Departments []uint64 `json:"departments" form:"departments"`
|
||||
Roles []uint64 `json:"roles" form:"roles"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
Account string `json:"account" form:"account" binding:"required"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Gender int `json:"gender" form:"gender" binding:"required"`
|
||||
DepartmentID string `json:"department_id" form:"department_id"`
|
||||
RoleIDs []string `json:"role_ids" form:"role_ids"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @apiDefine User 用户管理
|
||||
*/
|
||||
func (this *userForm) departmentInfo() uint64 {
|
||||
return (&api.IDStringForm{ID: this.DepartmentID}).Convert()
|
||||
}
|
||||
|
||||
func (a *User) Info(c *gin.Context) {
|
||||
func (this *userForm) RoleInfo() []uint64 {
|
||||
out := make([]uint64, 0)
|
||||
|
||||
obj := new(api.IDStringForm)
|
||||
|
||||
for _, v := range this.RoleIDs {
|
||||
obj.ID = v
|
||||
out = append(out, obj.Convert())
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (*User) Info(c *gin.Context) {
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Info()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
@ -46,7 +58,7 @@ func (a *User) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (a *User) Menu(c *gin.Context) {
|
||||
data, err := user.NewMenu()(api.GetSession()(c).(*session.Admin)).List()
|
||||
data, err := user.NewMenu()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -61,7 +73,7 @@ func (a *User) Add(c *gin.Context) {
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Add(&user.InstanceForm{
|
||||
Account: form.Account, Name: form.Name, Mobile: form.Mobile, Password: form.Password,
|
||||
Remark: form.Remark, Gender: form.Gender, Departments: form.Departments, Roles: form.Roles,
|
||||
Remark: form.Remark, Gender: form.Gender, DepartmentID: form.departmentInfo(), RoleIDs: form.RoleInfo(),
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -77,7 +89,7 @@ func (a *User) Edit(c *gin.Context) {
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Edit(&user.InstanceForm{
|
||||
ID: form.ID, Account: form.Account, Name: form.Name, Mobile: form.Mobile,
|
||||
Remark: form.Remark, Gender: form.Gender, Departments: form.Departments, Roles: form.Roles,
|
||||
Remark: form.Remark, Gender: form.Gender, DepartmentID: form.departmentInfo(), RoleIDs: form.RoleInfo(),
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user