75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package api
|
|
|
|
import (
|
|
"ArmedPolice/app/controller/basic"
|
|
"ArmedPolice/app/controller/tenant"
|
|
"ArmedPolice/app/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Tenant struct{}
|
|
|
|
type tenantForm struct {
|
|
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Remark string `json:"remark" form:"remark"`
|
|
Province string `json:"province" form:"province"`
|
|
City string `json:"city" form:"city"`
|
|
District string `json:"district" form:"district"`
|
|
Address string `json:"address" form:"address"`
|
|
}
|
|
|
|
/**
|
|
* @apiDefine Tenant 租户(单位)管理
|
|
*/
|
|
|
|
func (*Tenant) List(c *gin.Context) {
|
|
data, err := tenant.NewInstance()(getSession()(c).(*service.Session)).List()
|
|
APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Tenant) Add(c *gin.Context) {
|
|
form := new(tenantForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Form(&tenant.InstanceParams{
|
|
ParentID: form.ParentID, Name: form.Name, Remark: form.Remark,
|
|
CommonArea: basic.CommonArea{
|
|
Province: form.Province, City: form.City, District: form.District, Address: form.Address,
|
|
},
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Tenant) Edit(c *gin.Context) {
|
|
form := &struct {
|
|
IDStringForm
|
|
tenantForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Form(&tenant.InstanceParams{
|
|
ID: form.Convert(), ParentID: form.ParentID, Name: form.Name, Remark: form.Remark,
|
|
CommonArea: basic.CommonArea{
|
|
Province: form.Province, City: form.City, District: form.District, Address: form.Address,
|
|
},
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Tenant) Delete(c *gin.Context) {
|
|
form := new(IDStringForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
|
APIResponse(err)(c)
|
|
}
|