Files
2021-10-15 15:01:21 +08:00

68 lines
1.8 KiB
Go

package api
import (
"SciencesServer/app/manage/controller"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
type Department struct{}
type departmentForm struct {
ParentID uint64 `json:"parent_id" form:"parent_id"`
Title string `json:"title" form:"title" binding:"required"`
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
Remark string `json:"remark" form:"remark"`
}
func (a *Department) List(c *gin.Context) {
data, err := controller.NewDepartment()(getSession()(c).(*service.Session)).List()
APIResponse(err, data)(c)
}
func (a *Department) Select(c *gin.Context) {
data, err := controller.NewDepartment()(getSession()(c).(*service.Session)).Select()
APIResponse(err, data)(c)
}
func (a *Department) Add(c *gin.Context) {
form := new(departmentForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Data(&controller.DepartmentParams{
ParentID: form.ParentID, Title: form.Title, Name: form.Name, Mobile: form.Mobile, Remark: form.Remark,
})
APIResponse(err)(c)
}
func (a *Department) Edit(c *gin.Context) {
form := &struct {
idForm
departmentForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Data(&controller.DepartmentParams{
ID: form.ID, ParentID: form.ParentID, Title: form.Title, Name: form.Name, Mobile: form.Mobile, Remark: form.Remark,
})
APIResponse(err)(c)
}
func (a *Department) Delete(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Delete(form.ID)
APIResponse(err)(c)
}