Files
ArmedPolice/app/api/user.go

97 lines
2.4 KiB
Go
Raw Normal View History

2021-11-02 10:02:52 +08:00
package api
2021-11-02 17:01:04 +08:00
import (
"ArmedPolice/app/controller/user"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type User struct{}
2021-11-04 16:44:42 +08:00
/**
* @apiDefine User 用户管理
*/
/**
* @api {get} /api/v1/user/info 用户信息
* @apiVersion 1.0.0
* @apiName UserInfo
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Json} data 数据信息
* @apiSuccess (200) {String} data.name 用户名
* @apiSuccess (200) {String} data.avatar 用户头像
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "name": "商挈智能",
* "avatar": "",
* }
* }
*/
2021-11-02 17:01:04 +08:00
func (*User) Info(c *gin.Context) {
data := user.NewInstance()(getSession()(c).(*service.Session)).Info()
2021-11-04 16:16:57 +08:00
APIResponse(nil, data)(c)
2021-11-02 17:01:04 +08:00
}
2021-11-02 17:28:19 +08:00
2021-11-04 15:15:11 +08:00
func (*User) Menu(c *gin.Context) {
data, err := user.NewMenu()(getSession()(c).(*service.Session)).Menu()
2021-11-04 16:16:57 +08:00
APIResponse(err, data)(c)
2021-11-04 15:15:11 +08:00
}
2021-11-02 17:28:19 +08:00
func (*User) List(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID,
form.Page, form.PageSize)
2021-11-04 16:16:57 +08:00
APIResponse(err, data)(c)
2021-11-02 17:28:19 +08:00
}
func (*User) Add(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID,
form.Page, form.PageSize)
2021-11-04 16:16:57 +08:00
APIResponse(err, data)(c)
2021-11-02 17:28:19 +08:00
}
func (*User) Edit(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID,
form.Page, form.PageSize)
2021-11-04 16:16:57 +08:00
APIResponse(err, data)(c)
2021-11-02 17:28:19 +08:00
}