78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/controller/department"
|
|
"SciencesServer/app/basic/api"
|
|
"SciencesServer/app/session"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Department struct{}
|
|
|
|
type departmentForm struct {
|
|
ParentID string `json:"parent_id" form:"parent_id"`
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Contact string `json:"contact" form:"contact"`
|
|
ContactMobile string `json:"contact_mobile" form:"contact_mobile"`
|
|
Status int `json:"status" form:"status" binding:"required"`
|
|
Remark string `json:"remark" form:"remark"`
|
|
}
|
|
|
|
func (a *Department) Index(c *gin.Context) {
|
|
form := &struct {
|
|
FilterID string `json:"filter_id" form:"filter_id"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Index((&api.IDStringForm{ID: form.FilterID}).Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Department) Select(c *gin.Context) {
|
|
data, err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Select()
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Department) Add(c *gin.Context) {
|
|
form := new(departmentForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&department.InstanceParams{
|
|
ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(), Contact: form.Contact, Name: form.Name,
|
|
ContactMobile: form.ContactMobile, Status: form.Status, Remark: form.Remark,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Department) Edit(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
departmentForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&department.InstanceParams{
|
|
ID: form.Convert(), ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(), Contact: form.Contact,
|
|
Name: form.Name, ContactMobile: form.ContactMobile, Status: form.Status, Remark: form.Remark,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Department) Delete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := department.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|