From 1adc137e0e2071dfb379a34c533121a8bebf9143 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Sun, 26 Jan 2020 01:39:31 +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=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 31 ++++++++++++++++++++++--------- main.go | 5 ++--- model/blog.go | 10 ++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 3b4f2f9..46128b7 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -203,25 +203,38 @@ func ArticlesType(c *gin.Context) { rsp.Msg = "OK" rsp.Status = 0 } +func DeleteArticleType(c *gin.Context) { + rsp := RespBase{Msg:"Fail",Status:210} + defer func() { + c.JSON(200,rsp) + }() + sid :=c.Query("id") + if sid == ""{ + return + } + id ,e := strconv.Atoi(sid) + if nil != e{ + log.Print(e.Error()) + return + } + rsp.Data = model.DeleteArticleType(int32(id)) + rsp.Msg = "OK" + rsp.Status = 0 +} func AddArticleType(c *gin.Context) { rsp := RespBase{Msg:"Fail",Status:210} defer func() { c.JSON(200,rsp) }() - type ReqAddArticleType struct { - Id int64 `json:"id"` - Name string `json:"name"` - author string `json:"author"` - } - var req ReqAddArticleType - e := c.BindJSON(req) - if nil != e{ + + typeName :=c.Query("name") + if typeName == ""{ return } articleType := model.ArticleType{ Id: 0, - Name: req.Name, + Name: typeName, } rsp.Data = model.AddArticleType(articleType) rsp.Msg = "OK" diff --git a/main.go b/main.go index 57491fc..ba84326 100644 --- a/main.go +++ b/main.go @@ -44,8 +44,7 @@ func InitLogs() { } func CORSMiddleware(c *gin.Context) { c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") - c.Writer.Header().Set("Access-Control-Allow-Origin", - "http://localhost:8080") + c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080") c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With," + @@ -103,13 +102,13 @@ func main() { 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) ////删除文章 api.POST("/image_upload",fileController.OnUpload) // 上传图片 api.GET("/image_download/:file",fileController.OnDownLoad) // 下载图片 api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型 - } e := r.Run(":" + strconv.Itoa(config.GetPort())) diff --git a/model/blog.go b/model/blog.go index acf24b2..bfc3f8a 100644 --- a/model/blog.go +++ b/model/blog.go @@ -82,4 +82,14 @@ func AddArticleType(t ArticleType) 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) + if nil != e { + logs.Error(e.Error()) + return e + } + return nil + } \ No newline at end of file