no message
This commit is contained in:
parent
3521716370
commit
540229aa5e
@ -680,9 +680,6 @@ func GetMemos(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func GetDocTemplate(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func GetMemo(c *gin.Context) {
|
||||
rsp := RespBase{"ERR", -1, nil}
|
||||
@ -723,3 +720,82 @@ func DeleteMemos(c *gin.Context) {
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func CreateDocTemplate(c *gin.Context) {
|
||||
resp := RespBase{}
|
||||
defer func() {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
var req model.DocTemplate
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e {
|
||||
logs.Error(e.Error())
|
||||
resp.Msg = "wrong input"
|
||||
return
|
||||
}
|
||||
e = model.CreateDocTemplate(req)
|
||||
if nil != e{
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
resp.Data = nil
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func UpdateDocTemplate(c *gin.Context) {
|
||||
resp := RespBase{}
|
||||
defer func() {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
var req model.DocTemplate
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e {
|
||||
resp.Msg = "wrong input"
|
||||
return
|
||||
}
|
||||
e = model.UpdateDocTemplate(req)
|
||||
if nil != e {
|
||||
logs.Error(e.Error())
|
||||
return
|
||||
}
|
||||
resp.Data = nil
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
func GetDocTemplate(c *gin.Context) {
|
||||
type ReqGet struct{
|
||||
Title string `json:"title"`
|
||||
}
|
||||
req := ReqGet{}
|
||||
resp := RespBase{}
|
||||
defer func() {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e{
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
ret,e := model.GetDocTemplate(req.Title,5,0)
|
||||
if nil != e{
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
resp.Data = ret
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
func DeleteDocTemplate(c *gin.Context) {
|
||||
resp := RespBase{}
|
||||
defer func() {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
type ReqDeleteDocTemplate struct {
|
||||
}
|
||||
|
||||
}
|
6
main.go
6
main.go
@ -165,7 +165,6 @@ func main() {
|
||||
api.POST("type_group", controller.GetDocTypeGroup) // 获取类所在的组
|
||||
api.POST("group_type", controller.GetDoGroupcType) // 获取类所在的组
|
||||
|
||||
api.GET("templates", controller.GetDocTemplate) // 获取所有文章的模板
|
||||
|
||||
api.GET("doc_versions", nil) // 获取文章的某个版本
|
||||
|
||||
@ -187,6 +186,11 @@ func main() {
|
||||
api.GET("/undo", planController.GetUndo)
|
||||
api.DELETE("/undo/:id", planController.DeleteUndo)
|
||||
|
||||
|
||||
api.PUT("/doc_template",controller.CreateDocTemplate)
|
||||
api.POST("/doc_template",controller.UpdateDocTemplate)
|
||||
api.POST("/get_doc_template",controller.GetDocTemplate)
|
||||
api.DELETE("/doc_template/:id",controller.DeleteDocTemplate)
|
||||
}
|
||||
|
||||
openapi := r.Group("openapi")
|
||||
|
@ -10,14 +10,12 @@ import (
|
||||
type DocTemplate struct {
|
||||
Id int32 `sql:"id" json:"id"`
|
||||
Content string `sql:"content" json:"content"`
|
||||
Name string `sql:"content" json:"name"`
|
||||
Name string `sql:"name" json:"name"`
|
||||
}
|
||||
|
||||
|
||||
func CreateDocTemplate(templ DocTemplate) error{
|
||||
sql := fmt.Sprintf(`insert into doc_template(content,name) select '%s','%s
|
||||
from dual where not exists (select * from doc_template where doc_template.name='%s') `,
|
||||
templ.Content,templ.Name,templ.Name)
|
||||
sql := fmt.Sprintf(`insert into doc_template(content,name) values('%s','%s')`,templ.Content,templ.Name)
|
||||
log.Print(sql)
|
||||
_, e := db.GetMysqlClient().Query(sql)
|
||||
if nil != e {
|
||||
@ -28,8 +26,8 @@ func CreateDocTemplate(templ DocTemplate) error{
|
||||
}
|
||||
|
||||
func UpdateDocTemplate(templ DocTemplate) error{
|
||||
sql := fmt.Sprintf(`update doc_template set content = %s,
|
||||
name = %s, where memo.id = '%d'`,templ.Content,templ.Name,templ.Id)
|
||||
sql := fmt.Sprintf(`update doc_template set content = '%s',name = '%s' where doc_template.id = %d`,templ.Content,templ.Name,templ.Id)
|
||||
log.Print(sql)
|
||||
_, e := db.GetMysqlClient().Query(sql)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
@ -61,8 +59,8 @@ func ReadDocTemplate(id int32) ([]DocTemplate,error){
|
||||
|
||||
func GetDocTemplate(title string,limit int,offset int) ([]DocTemplate,error) {
|
||||
memo := []DocTemplate{}
|
||||
sql := fmt.Sprintf(`select * from doc_template where doc_template.name like '%s%%' limit %d offset %d`,
|
||||
title,limit,offset)
|
||||
sql := fmt.Sprintf(`select * from doc_template limit %d offset %d`,
|
||||
limit,offset)
|
||||
log.Print(sql)
|
||||
e := db.GetMysqlClient().Query2(sql,&memo)
|
||||
if nil != e {
|
||||
|
Loading…
Reference in New Issue
Block a user