完善分类管理接口
parent
1adc137e0e
commit
9bdb4a833d
|
@ -229,6 +229,19 @@ func AddArticleType(c *gin.Context) {
|
|||
}()
|
||||
|
||||
typeName :=c.Query("name")
|
||||
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
|
||||
}
|
||||
|
@ -239,6 +252,8 @@ func AddArticleType(c *gin.Context) {
|
|||
rsp.Data = model.AddArticleType(articleType)
|
||||
rsp.Msg = "OK"
|
||||
rsp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
2
main.go
2
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) ////删除文章
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue