From 9bdb4a833da84819abe65ebcb76a1383122c34d1 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Sun, 26 Jan 2020 19:11:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=88=86=E7=B1=BB=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 33 ++++++++++++++++++++++++--------- main.go | 2 ++ model/blog.go | 10 ++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 46128b7..d6698dc 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -229,16 +229,31 @@ func AddArticleType(c *gin.Context) { }() typeName :=c.Query("name") - if typeName == ""{ - return + id := c.Query("id") + if id != ""{ + if typeName == ""{ + return + } + articleType := model.ArticleType{ + Id: 0, + Name: typeName, + } + rsp.Data = model.UpdateArticleType(articleType) + rsp.Msg = "OK" + rsp.Status = 0 + }else{ + if typeName == ""{ + return + } + articleType := model.ArticleType{ + Id: 0, + Name: typeName, + } + rsp.Data = model.AddArticleType(articleType) + rsp.Msg = "OK" + rsp.Status = 0 } - articleType := model.ArticleType{ - Id: 0, - Name: typeName, - } - rsp.Data = model.AddArticleType(articleType) - rsp.Msg = "OK" - rsp.Status = 0 + } diff --git a/main.go b/main.go index ba84326..f948257 100644 --- a/main.go +++ b/main.go @@ -100,9 +100,11 @@ func main() { api.GET("/article/:id",controller.GetArticle) //获取文章 api.POST("/articles",controller.GetArticles) // 获取所有文章 api.PUT("/article",controller.AddArticle) // 添加文章 + api.GET("article_type",controller.ArticlesType) //获取所有文章分类 api.PUT("article_type",controller.AddArticleType) api.DELETE("article_type",controller.DeleteArticleType) + api.POST("/article_update",controller.UpdateArtilce) //更新文章 api.GET("/articleCount",controller.GetArticleCount) //获取所有文章个数 api.DELETE("/article/:id",controller.DeleteArticle) ////删除文章 diff --git a/model/blog.go b/model/blog.go index bfc3f8a..2329a37 100644 --- a/model/blog.go +++ b/model/blog.go @@ -83,6 +83,16 @@ func AddArticleType(t ArticleType) error{ } return nil } +func UpdateArticleType(t ArticleType) error{ + sql := fmt.Sprintf("update doc_type set type_name = '%s' where id = %d",t.Name,t.Id) + _, e := db.GetMysqlClient().Query(sql) + if nil != e { + logs.Error(e.Error()) + return e + } + return nil + +} func DeleteArticleType(id int32) error { sql := fmt.Sprintf("delete from doc_type where id = '%d'",id) _, e := db.GetMysqlClient().Query(sql)