feat:完善项目

This commit is contained in:
henry
2021-11-02 10:02:52 +08:00
parent 4734344985
commit 690cd96bed
72 changed files with 5516 additions and 8 deletions

115
app/api/user.go Normal file
View File

@ -0,0 +1,115 @@
package api
import (
"ArmedPolice/app/controller/user"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
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"`
}
/**
* @apiDefine User 用户管理
*/
func (a *User) Info(c *gin.Context) {
data, err := user.NewInstance()(getSession()(c).(*service.Session)).Info()
APIResponse(err, data)(c)
}
func (a *User) List(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
Status int `json:"status" form:"status"`
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.Status, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
func (a *User) Add(c *gin.Context) {
form := &struct {
userForm
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)).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,
})
APIResponse(err)(c)
}
func (a *User) Edit(c *gin.Context) {
form := &struct {
idForm
userForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).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,
})
APIResponse(err)(c)
}
func (a *User) Password(c *gin.Context) {
form := &struct {
idForm
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)).Password(form.ID, form.Password, form.RepeatPwd)
APIResponse(err)(c)
}
func (a *User) EditPassword(c *gin.Context) {
form := &struct {
OldPwd string `json:"old_pwd" form:"old_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.NewPerson()(getSession()(c).(*service.Session)).EditPassword(form.OldPwd, form.Password, form.RepeatPwd)
APIResponse(err)(c)
}
func (a *User) Delete(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
APIResponse(err)(c)
}