完善分类管理模块

master
a7458969 2020-01-26 01:39:31 +08:00
parent dc1e6c6f5b
commit 1adc137e0e
3 changed files with 34 additions and 12 deletions

View File

@ -203,25 +203,38 @@ func ArticlesType(c *gin.Context) {
rsp.Msg = "OK" rsp.Msg = "OK"
rsp.Status = 0 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) { func AddArticleType(c *gin.Context) {
rsp := RespBase{Msg:"Fail",Status:210} rsp := RespBase{Msg:"Fail",Status:210}
defer func() { defer func() {
c.JSON(200,rsp) c.JSON(200,rsp)
}() }()
type ReqAddArticleType struct {
Id int64 `json:"id"` typeName :=c.Query("name")
Name string `json:"name"` if typeName == ""{
author string `json:"author"`
}
var req ReqAddArticleType
e := c.BindJSON(req)
if nil != e{
return return
} }
articleType := model.ArticleType{ articleType := model.ArticleType{
Id: 0, Id: 0,
Name: req.Name, Name: typeName,
} }
rsp.Data = model.AddArticleType(articleType) rsp.Data = model.AddArticleType(articleType)
rsp.Msg = "OK" rsp.Msg = "OK"

View File

@ -44,8 +44,7 @@ func InitLogs() {
} }
func CORSMiddleware(c *gin.Context) { 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-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Writer.Header().Set("Access-Control-Allow-Origin", c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080")
"http://localhost:8080")
c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Max-Age", "86400")
c.Writer.Header().Set("Access-Control-Allow-Headers", c.Writer.Header().Set("Access-Control-Allow-Headers",
"X-Requested-With," + "X-Requested-With," +
@ -103,13 +102,13 @@ func main() {
api.PUT("/article",controller.AddArticle) // 添加文章 api.PUT("/article",controller.AddArticle) // 添加文章
api.GET("article_type",controller.ArticlesType) //获取所有文章分类 api.GET("article_type",controller.ArticlesType) //获取所有文章分类
api.PUT("article_type",controller.AddArticleType) api.PUT("article_type",controller.AddArticleType)
api.DELETE("article_type",controller.DeleteArticleType)
api.POST("/article_update",controller.UpdateArtilce) //更新文章 api.POST("/article_update",controller.UpdateArtilce) //更新文章
api.GET("/articleCount",controller.GetArticleCount) //获取所有文章个数 api.GET("/articleCount",controller.GetArticleCount) //获取所有文章个数
api.DELETE("/article/:id",controller.DeleteArticle) ////删除文章 api.DELETE("/article/:id",controller.DeleteArticle) ////删除文章
api.POST("/image_upload",fileController.OnUpload) // 上传图片 api.POST("/image_upload",fileController.OnUpload) // 上传图片
api.GET("/image_download/:file",fileController.OnDownLoad) // 下载图片 api.GET("/image_download/:file",fileController.OnDownLoad) // 下载图片
api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型 api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型
} }
e := r.Run(":" + strconv.Itoa(config.GetPort())) e := r.Run(":" + strconv.Itoa(config.GetPort()))

View File

@ -82,4 +82,14 @@ func AddArticleType(t ArticleType) error{
return e return e
} }
return nil 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
} }