完善分类管理模块
parent
dc1e6c6f5b
commit
1adc137e0e
|
@ -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"
|
||||
|
|
5
main.go
5
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()))
|
||||
|
|
|
@ -83,3 +83,13 @@ func AddArticleType(t ArticleType) error{
|
|||
}
|
||||
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
|
||||
|
||||
}
|
Loading…
Reference in New Issue