From 540229aa5e15c0093abbb0bcf31e4f1460f7b28f Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Fri, 26 Mar 2021 13:13:23 +0800 Subject: [PATCH] no message --- controller/blog.go | 82 ++++++++++++++++++++++++++++++++++++++++++++-- main.go | 6 +++- model/template.go | 14 ++++---- 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 7b4105b..e6ca7f3 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -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 { + } + +} \ No newline at end of file diff --git a/main.go b/main.go index f71ea4d..1673efc 100644 --- a/main.go +++ b/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") diff --git a/model/template.go b/model/template.go index f618c48..ed15694 100644 --- a/model/template.go +++ b/model/template.go @@ -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 {