Files
2021-10-13 11:23:55 +08:00

82 lines
2.6 KiB
Go

package api
import (
"SciencesServer/app/basic/api"
"SciencesServer/app/enterprise/controller/technology"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
type Technology struct{}
type (
// paperForm 论文参数
paperForm struct {
Title string `json:"title" form:"title" binding:"required"` // 题目
Ext string `json:"ext" form:"ext" binding:"required"` // 格式
Author string `json:"author" form:"author" binding:"required"` // 作者
PublishAt string `json:"publish_at" form:"publish_at" binding:"required"` // 出版日期
Keyword string `json:"keyword" form:"keyword"` // 关键词
Tags []string `json:"tags" form:"tags"` // 标签
Remark string `json:"remark" form:"remark"` // 备注
}
)
func (a *Technology) Paper(c *gin.Context) {
form := &struct {
Title string `json:"title"`
api.PageForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)).
List(form.Title, form.Page, form.PageSize)
api.APIResponse(err, data)
}
func (a *Technology) PaperAdd(c *gin.Context) {
form := new(paperForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)).
Form(&technology.PaperParams{
Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
})
api.APIResponse(err)
}
func (a *Technology) PaperEdit(c *gin.Context) {
form := &struct {
api.IDStringForm
paperForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)).
Form(&technology.PaperParams{
ID: form.Convert(), Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
})
api.APIResponse(err)
}
func (a *Technology) PaperDelete(c *gin.Context) {
form := new(api.IDStringForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(uint64)).
Delete(form.Convert())
api.APIResponse(err)
}