300 lines
9.1 KiB
Go
300 lines
9.1 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/controller/service"
|
|
"SciencesServer/app/basic/api"
|
|
"SciencesServer/app/session"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Service struct{}
|
|
|
|
func (*Service) Innovate(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title"`
|
|
KindID string `json:"kind_id" form:"kind_id"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title,
|
|
(&api.IDStringForm{ID: form.KindID}).Convert(), form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) InnovateDetail(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) InnovateForm(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.TenantIDStringForm
|
|
KindID string `json:"kind_id" form:"kind_id" binding:"required"`
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
Description string `json:"description" form:"description"`
|
|
Content string `json:"content" form:"content" binding:"required"`
|
|
Tags []string `json:"tags" form:"tags"`
|
|
Sort int `json:"sort" form:"sort"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).Form(&service.InnovateParams{
|
|
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(),
|
|
KindID: (&api.IDStringForm{ID: form.KindID}).Convert(), Title: form.Title, Description: form.Description,
|
|
Content: form.Content, Tags: form.Tags, Sort: form.Sort,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) InnovateDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) InnovateKind(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).Kind(form.Convert(), form.Title, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) InnovateKindSelect(c *gin.Context) {
|
|
data, err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).KindSelect()
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) InnovateKindForm(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
Sort int `json:"sort" form:"sort"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).KindForm(&service.InnovateKindParams{
|
|
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(), Title: form.Title, Sort: form.Sort,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) InnovateKindDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewInnovate()(api.GetSession()(c).(*session.Admin)).KindDelete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCase(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title"`
|
|
KindID uint64 `json:"kind_id" form:"kind_id"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title, form.KindID,
|
|
form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseDetail(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseForm(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.TenantIDStringForm
|
|
KindID string `json:"kind_id" form:"kind_id" binding:"required"`
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
api.ImageForm
|
|
Description string `json:"description" form:"description" binding:"required"`
|
|
Content string `json:"content" form:"content" binding:"required"`
|
|
Sort int `json:"sort" form:"sort"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).Form(&service.SolutionCaseParams{
|
|
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(), KindID: (&api.IDStringForm{ID: form.KindID}).Convert(),
|
|
Image: form.FilterImageURL(), Title: form.Title, Description: form.Description, Content: form.Content, Sort: form.Sort,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseKind(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Mode int `json:"mode" form:"mode"`
|
|
Title string `json:"title" form:"title"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).Kind(form.Convert(), form.Mode, form.Title, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseKindSelect(c *gin.Context) {
|
|
data, err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).KindSelect()
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseKindForm(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
api.TenantIDStringForm
|
|
Mode int `json:"mode" form:"mode" binding:"required"`
|
|
Title string `json:"title" form:"title" binding:"required"`
|
|
api.ImageForm
|
|
Sort int `json:"sort" form:"sort"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).KindForm(&service.SolutionCaseKindParams{
|
|
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(), Mode: form.Mode,
|
|
Image: form.FilterImageURL(), Title: form.Title, Sort: form.Sort,
|
|
})
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) SolutionCaseKindDelete(c *gin.Context) {
|
|
form := new(api.IDStringForm)
|
|
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).KindDelete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) Message(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Name string `json:"name" form:"name"`
|
|
Status int `json:"status" form:"status"`
|
|
Content string `json:"content" form:"content"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Instance(form.TenantIDStringForm.Convert(),
|
|
form.Name, form.Status, form.Content, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) MessageHandle(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
Content string `json:"content" form:"content"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Handle(form.Convert(), form.Content)
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) MessageDelete(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Service) Demand(c *gin.Context) {
|
|
form := &struct {
|
|
api.TenantIDStringForm
|
|
Title string `json:"title" form:"title"`
|
|
Kind int `json:"kind" form:"kind"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := service.NewDemand()(api.GetSession()(c).(*session.Admin)).Instance(form.TenantIDStringForm.Convert(),
|
|
form.Title, form.Kind, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (*Service) DemandDelete(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := service.NewDemand()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
|
api.APIResponse(err)(c)
|
|
}
|