94 lines
2.9 KiB
Go
94 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/enterprise/controller/activity"
|
|
"SciencesServer/app/basic/api"
|
|
"SciencesServer/app/session"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Activity struct{}
|
|
|
|
func (*Activity) Applys(c *gin.Context) {
|
|
form := &struct {
|
|
Title string `json:"title" form:"title"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise)).Instance(form.Title, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) ApplyLaunch(c *gin.Context) {
|
|
form := &struct {
|
|
Mode int `json:"mode" form:"mode" binding:"required"`
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
Amount float64 `json:"amount" form:"amount"`
|
|
Content string `json:"content" form:"content"`
|
|
MaxNumber int `json:"max_number" form:"max_number"`
|
|
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"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise)).Launch(&activity.ApplyLaunchParams{
|
|
Mode: form.Mode, MaxNUmber: form.MaxNumber, Title: form.Title, Amount: form.Amount, Content: form.Content,
|
|
BeginAt: form.BeginAt, FinishAt: form.FinishAt, JoinDeadline: form.JoinDeadline,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Activity) ApplyRevoke(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise)).Revoke(form.Convert())
|
|
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
|
|
}
|
|
err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Activity) Joins(c *gin.Context) {
|
|
form := &struct {
|
|
Title string `json:"title" form:"title"`
|
|
Status int `json:"status" form:"status"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := activity.NewInstance()(api.GetSession()(c).(*session.Enterprise)).Joins(form.Title, form.Status, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Activity) JoinDelete(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.Enterprise)).JoinDelete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|