feat:完善项目

This commit is contained in:
henry
2021-11-09 16:32:36 +08:00
parent be0ef1a1d0
commit 1c00a7c328
6 changed files with 536 additions and 35 deletions

View File

@ -1,17 +1,28 @@
package api
import (
model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/controller/user"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type User struct{}
/**
* @apiDefine User 用户管理
*/
type User struct{}
type userForm struct {
Account string `json:"account" form:"account" binding:"required"`
Name string `json:"name" form:"name" binding:"required"`
Avatar string `json:"avatar" form:"avatar"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Password string `json:"password" form:"password"`
Gender int `json:"gender" form:"gender"`
Remark string `json:"remark" form:"remark"`
}
/**
* @api {get} /api/v1/user/info 用户信息
* @apiVersion 1.0.0
@ -20,11 +31,11 @@ type User struct{}
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Json} data 数据信息
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.name 用户名
* @apiSuccess (200) {String} data.avatar 用户头像
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
@ -63,34 +74,273 @@ func (*User) List(c *gin.Context) {
APIResponse(err, data)(c)
}
/**
* @api {get} /api/v1/user/add 用户信息添加
* @apiVersion 1.0.0
* @apiName UserAdd
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} account 登陆账号
* @apiParam {String} name 姓名
* @apiParam {String} [avatar="''"] 头像
* @apiParam {String} mobile 手机号
* @apiParam {String} password 密码
* @apiParam {Number} gender 性别12
* @apiParam {String} [remark="''"] 备注信息
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.name 用户名
* @apiSuccess (200) {String} data.avatar 用户头像
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
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
}{}
form := new(userForm)
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)
APIResponse(err, data)(c)
obj := &ImageForm{Image: form.Avatar}
err := user.NewInstance()(getSession()(c).(*service.Session)).Form(&user.InstanceParams{
Account: form.Account, Name: form.Name, Avatar: obj.FilterImageURL(), Mobile: form.Mobile,
Password: form.Password, Remark: form.Remark, Gender: form.Gender,
})
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/user/edit 用户信息修改
* @apiVersion 1.0.0
* @apiName UserEdit
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} account 登陆账号
* @apiParam {String} name 姓名
* @apiParam {String} [avatar="''"] 头像
* @apiParam {String} mobile 手机号
* @apiParam {Number} gender 性别12
* @apiParam {String} [remark="''"] 备注信息
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.name 用户名
* @apiSuccess (200) {String} data.avatar 用户头像
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
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
IDStringForm
userForm
}{}
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)
APIResponse(err, data)(c)
obj := &ImageForm{Image: form.Avatar}
err := user.NewInstance()(getSession()(c).(*service.Session)).Form(&user.InstanceParams{
ID: form.Convert(), Account: form.Account, Name: form.Name, Avatar: obj.FilterImageURL(),
Mobile: form.Mobile, Password: form.Password, Remark: form.Remark, Gender: form.Gender,
})
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/user/delete 用户信息删除
* @apiVersion 1.0.0
* @apiName UserDelete
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*User) Delete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/user/password/quick 用户密码快速设置
* @apiVersion 1.0.0
* @apiName UserPasswordQuick
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} passowrd 密码
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Json} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*User) PasswordQuick(c *gin.Context) {
form := &struct {
IDStringForm
Password string `json:"password" form:"password" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).PasswordQuick(form.Convert(), form.Password)
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/user/password/tradition 用户密码传统设置
* @apiVersion 1.0.0
* @apiName UserPasswordTradition
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} original_pwd 旧密码
* @apiParam {String} passowrd 新密码
* @apiParam {String} repeat_pwd 重复密码
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Json} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*User) PasswordTradition(c *gin.Context) {
form := &struct {
IDStringForm
OriginalPwd string `json:"original_pwd" form:"original_pwd" binding:"required"`
Password string `json:"password" form:"password" binding:"required"`
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).PasswordTradition(form.Convert(),
form.OriginalPwd, form.Password, form.RepeatPwd)
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/user/password/activate 用户账号激活
* @apiVersion 1.0.0
* @apiName UserPasswordActivate
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Json} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*User) Activate(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Status(form.Convert(), model2.SysUserStatusForNormal)
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/user/password/frozen( 用户账号冻结
* @apiVersion 1.0.0
* @apiName UserPasswordFrozen(
* @apiGroup User
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Json} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*User) Frozen(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Status(form.Convert(), model2.SysUserStatusForDisable)
APIResponse(err)(c)
}