154 lines
5.2 KiB
Go
154 lines
5.2 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/controller/activity"
|
|
"SciencesServer/app/basic/api"
|
|
"SciencesServer/app/basic/config"
|
|
"SciencesServer/app/session"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Activity struct{}
|
|
|
|
func (*Activity) Instance(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title"`
|
|
Contact string `json:"contact" form:"contact"`
|
|
ContactMobile string `json:"contact_mobile" form:"contact_mobile"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Convert(), form.Title,
|
|
form.Contact, form.ContactMobile, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) Detail(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewInstance()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) Form(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
ApplyID string `json:"apply_id" form:"apply_id"`
|
|
api.TenantIDStringForm
|
|
api.ImageForm
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
Description string `json:"description" form:"description" binding:"required"`
|
|
Content string `json:"content" form:"content" binding:"required"`
|
|
Contact string `json:"contact" form:"contact" binding:"required"`
|
|
ContactMobile string `json:"contact_mobile" form:"contact_mobile"`
|
|
BeginAt string `json:"begin_at" form:"begin_at" binding:"required"`
|
|
FinishAt string `json:"finish_at" form:"finish_at" binding:"required"`
|
|
JoinDeadline string `json:"join_deadline" form:"join_deadline" binding:"required"`
|
|
config.Area
|
|
Industrys []string `json:"industrys" form:"industrys"`
|
|
Amount float64 `json:"amount" form:"amount"`
|
|
MaxNumber int `json:"max_number" form:"max_number"`
|
|
NotifyCrowd int `json:"notify_crowd" form:"notify_crowd"`
|
|
IsHome int `json:"is_home" form:"is_home"`
|
|
Sort int `json:"sort" form:"sort"`
|
|
Status int `json:"status" form:"status"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := activity.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&activity.InstanceParams{
|
|
ID: form.IDStringForm.Convert(), ApplyID: (&api.IDStringForm{ID: form.ApplyID}).Convert(),
|
|
TenantID: form.TenantIDStringForm.Convert(), Title: form.Title, Contact: form.Contact, ContactMobile: form.ContactMobile,
|
|
Image: form.FilterImageURL(), Description: form.Description, Content: form.Content, BeginAt: form.BeginAt, FinishAt: form.FinishAt,
|
|
JoinDeadline: form.JoinDeadline, Area: form.Area, Industrys: form.Industrys, Amount: form.Amount,
|
|
MaxNumber: form.MaxNumber, NotifyCrowd: form.NotifyCrowd, IsHome: form.IsHome, Sort: form.Sort, Status: form.Status,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Activity) Delete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := activity.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Activity) Joins(c *gin.Context) {
|
|
form := &struct {
|
|
ActivityID string `json:"activity_id" form:"activity_id" binding:"required"`
|
|
Name string `json:"name" form:"name"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewInstance()(api.GetSession()(c).(*session.Admin)).Joins(
|
|
(&api.IDStringForm{ID: form.ActivityID}).Convert(), form.Name, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) Apply(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title"`
|
|
Contact string `json:"contact" form:"contact"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewApply()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title,
|
|
form.Contact, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) ApplyDetail(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewApply()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) ApplyHandle(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
Remark string `json:"remark" form:"remark"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := activity.NewApply()(api.GetSession()(c).(*session.Admin)).Handle(form.Convert(), form.Remark)
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Activity) ApplyDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewApply()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|