From 319ea4a6791b1e7221e61823bc0395e7ea66792e Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Mon, 14 Nov 2022 00:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=96=B0=E5=A2=9E=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=89=88=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.go | 2 +- model/blog.go | 23 +++++++++-------------- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 50d8513..bce35f0 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -208,8 +208,52 @@ func GetArticleCount(c *gin.Context) { resp.Msg = "OK" } +// InsertDocHistory +func AddArticleHistory(c *gin.Context) { + rsp := RespBase{Msg: "FAIL", Status: 211} + type ReqUpdateArticle struct { + ID int64 `json:"id"` + Title string `json:"title"` + Content string `json:"content"` + Author string `json:"author"` + Type int64 `json:"type"` + IsPublic int `json:"is_public"` + Father int `json:"father"` + Level int `json:"level"` + } + var req ReqUpdateArticle + defer func() { + c.JSON(200, rsp) + }() + er := c.BindJSON(&req) + if nil != er { + logs.Error(er.Error()) + return + } + if req.Title == "" { + rsp.Msg = "title required" + return + } + + e := model.InsertDocHistory(model.DocTree{ + ID: (req.ID), + Type: int32(req.Type), + Title: req.Title, + Content: req.Content, + Author: req.Author, + Father: int32(req.Father), + Level: int32(req.Level), + },) + if(nil != e){ + logs.Error(er.Error()) + return + } + rsp.Msg = "OK" + rsp.Status = 0 + +} func GetArticleHistory(c *gin.Context) { resp := RespBase{Msg: "FAIL", Status: 211} defer func() { diff --git a/main.go b/main.go index 03447f6..72d04f9 100644 --- a/main.go +++ b/main.go @@ -163,7 +163,7 @@ func main() { api.PUT("/article", controller.AddArticle) // 添加文章 api.PUT("/article_tree", controller.AddArticleTree) // 添加文章 - api.PUT("/article_tree_history", controller.AddArticleTree) // 添加文章 + api.PUT("/article_tree_history", controller.AddArticleHistory) // 添加文章 api.PUT("/article_search", controller.SearchArticles) // 添加文章 api.GET("/article_type", controller.ArticlesType) //获取所有文章分类 diff --git a/model/blog.go b/model/blog.go index 50625db..a015426 100644 --- a/model/blog.go +++ b/model/blog.go @@ -167,16 +167,18 @@ func UpdateDoc(doc Doc) error { logs.Error(e.Error()) return e } - sql = fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`, - doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05")) - _, er := db.GetMysqlClient().Query(sql) - if nil != er { - logs.Error(e.Error()) - return e - } + // sql = fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`, + // doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05")) + // _, er := db.GetMysqlClient().Query(sql) + // if nil != er { + // logs.Error(e.Error()) + // return e + // } return nil } + +// 添加文件版本。 func InsertDocHistory(doc DocTree) error{ sql := fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`, doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05")) @@ -202,13 +204,6 @@ func UpdateDocTree(doc DocTree) error { logs.Error(e.Error()) return e } - // sql = fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`, - // doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05")) - // _, er := db.GetMysqlClient().Query(sql) - // if nil != er { - // logs.Error(e.Error()) - // return e - // } return nil }