155 lines
5.0 KiB
Go
155 lines
5.0 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/controller/tenant"
|
|
"SciencesServer/app/basic/api"
|
|
"SciencesServer/app/basic/config"
|
|
"SciencesServer/app/session"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Tenant struct{}
|
|
|
|
type (
|
|
// tenantForm 基本信息
|
|
tenantForm struct {
|
|
Name string `json:"name" form:"name" binding:"required"` // 名称
|
|
Domain string `json:"domain" form:"domain" binding:"required"` // 域名
|
|
Contact string `json:"contact" form:"contact" binding:"required"` // 联系人
|
|
ContactMobile string `json:"contact_mobile" form:"contact_mobile" binding:"required"` // 联系方式
|
|
Province string `json:"province" form:"province" binding:"required"` // 省
|
|
City string `json:"city" form:"city" binding:"required"` // 市区
|
|
Remark string `json:"remark" form:"remark"` // 备注
|
|
}
|
|
)
|
|
|
|
func (a *Tenant) Instance(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := tenant.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Name, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Tenant) Add(c *gin.Context) {
|
|
form := new(tenantForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&tenant.InstanceParams{Name: form.Name,
|
|
Domain: form.Domain, Contact: form.Contact, ContactMobile: form.ContactMobile,
|
|
Area: config.Area{Province: form.Province, City: form.City}, Remark: form.Remark,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Tenant) Edit(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
tenantForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&tenant.InstanceParams{ID: form.Convert(),
|
|
Name: form.Name, Domain: form.Domain, Contact: form.Contact, ContactMobile: form.ContactMobile,
|
|
Area: config.Area{Province: form.Province, City: form.City}, Remark: form.Remark,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Tenant) Delete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Tenant) Member(c *gin.Context) {
|
|
form := &struct {
|
|
TenantID string `json:"tenant_id" form:"tenant_id" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Instance((&api.IDStringForm{ID: form.TenantID}).Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Tenant) MemberBind(c *gin.Context) {
|
|
form := &struct {
|
|
TenantID string `json:"tenant_id" form:"tenant_id" binding:"required"`
|
|
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
|
Password string `json:"password" form:"password" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Form((&api.IDStringForm{ID: form.TenantID}).Convert(),
|
|
&tenant.MemberParams{Mobile: form.Mobile, Password: form.Password})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Tenant) Menu(c *gin.Context) {
|
|
form := &struct {
|
|
TenantID string `json:"tenant_id" form:"tenant_id" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := tenant.NewMenu()(api.GetSession()(c).(*session.Admin)).List((&api.IDStringForm{ID: form.TenantID}).Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Tenant) MenuBind(c *gin.Context) {
|
|
form := &struct {
|
|
TenantID string `json:"tenant_id" form:"tenant_id" binding:"required"`
|
|
MenuIDs []string `json:"menu_ids" form:"menu_ids" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
menuIDs := make([]uint64, 0)
|
|
|
|
for _, v := range form.MenuIDs {
|
|
menuIDs = append(menuIDs, (&api.IDStringForm{ID: v}).Convert())
|
|
}
|
|
err := tenant.NewMenu()(api.GetSession()(c).(*session.Admin)).Bind((&api.IDStringForm{ID: form.TenantID}).Convert(), menuIDs)
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Tenant) AuthBind(c *gin.Context) {
|
|
form := &struct {
|
|
TenantID string `json:"tenant_id" form:"tenant_id" binding:"required"`
|
|
AuthIDs []string `json:"auth_ids" form:"auth_ids" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
authIDs := make([]uint64, 0)
|
|
|
|
for _, v := range form.AuthIDs {
|
|
authIDs = append(authIDs, (&api.IDStringForm{ID: v}).Convert())
|
|
}
|
|
err := tenant.NewAuth()(api.GetSession()(c).(*session.Admin)).Bind((&api.IDStringForm{ID: form.TenantID}).Convert(), authIDs)
|
|
api.APIResponse(err)(c)
|
|
}
|