Files
ArmedPolice/app/api/auth.go

102 lines
2.4 KiB
Go
Raw Normal View History

2021-11-02 10:02:52 +08:00
package api
import (
"ArmedPolice/app/controller/auth"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Auth struct{}
/**
* @apiDefine Auth 权限管理
*/
func (a *Auth) List(c *gin.Context) {
data, err := auth.NewInstance()(getSession()(c).(*service.Session)).List()
APIResponse(err, data)(c)
}
/**
* @api {post} /api/auth/tenant/bind 租户权限绑定
* @apiVersion 1.0.0
* @apiName AuthTenantBind
* @apiGroup Auth
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} tenant_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 *Auth) TenantBind(c *gin.Context) {
form := &struct {
TenantID uint64 `json:"tenant_id" form:"tenant_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 := auth.NewTenant()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
APIResponse(err)(c)
}
func (a *Auth) Role(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 := auth.NewRole()(getSession()(c).(*service.Session)).List(form.RoleID)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/auth/role/bind 角色权限绑定
* @apiVersion 1.0.0
* @apiName AuthRoleBind
* @apiGroup Auth
*
* @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 *Auth) RoleBind(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 := auth.NewRole()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
APIResponse(err)(c)
}