blog_backend_api/controller/blog.go

41 lines
683 B
Go
Raw Normal View History

2019-05-16 10:05:20 +00:00
package controller
import (
"background/logs"
"background/model"
"github.com/gin-gonic/gin"
)
func AddArticle(c *gin.Context) {
rsp := RespBase{Msg:"FAIL", Status:210,}
type ReqAddArticle struct {
Title string `json:"title"`
Content string `json:"content"`
author string `json:"author"`
Type int64 `json:"type"`
}
var req ReqAddArticle
defer func() {
c.JSON(200,rsp)
}()
er := c.BindJSON(&req)
if nil != er{
logs.Error(er.Error())
return
}
e := model.CreateDoc(
model.Doc{
Type:req.Type,
Title:req.Title,
Content:req.Content,
Author:req.author,
},
)
if nil != e{
logs.Error(e.Error())
return
}
rsp.Msg = "OK"
rsp.Status = 0
}