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

107
app/api/role.go Normal file
View File

@ -0,0 +1,107 @@
package api
import (
"ArmedPolice/app/controller/role"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Role struct{}
func (a *Role) List(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Status int `json:"status" form:"status"`
pageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := role.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
func (a *Role) Select(c *gin.Context) {
data, err := role.NewInstance()(getSession()(c).(*service.Session)).Select()
APIResponse(err, data)(c)
}
func (a *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)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Data(0, form.Name, form.Remark, form.Sort)
APIResponse(err)(c)
}
func (a *Role) Edit(c *gin.Context) {
form := &struct {
idForm
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)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Data(form.ID, form.Name, form.Remark, form.Sort)
APIResponse(err)(c)
}
func (a *Role) Status(c *gin.Context) {
form := &struct {
idForm
Status int `json:"status" form:"status" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
APIResponse(err)(c)
}
func (a *Role) Delete(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
APIResponse(err)(c)
}
func (a *Role) User(c *gin.Context) {
form := &struct {
uidForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := role.NewUser()(getSession()(c).(*service.Session)).List(form.Convert())
APIResponse(err, data)(c)
}
func (a *Role) UserBind(c *gin.Context) {
form := &struct {
uidForm
RoleIDs []uint64 `json:"role_ids" form:"role_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewUser()(getSession()(c).(*service.Session)).Bind(form.Convert(), form.RoleIDs)
APIResponse(err)(c)
}