后台新增保存版本功能

master
zcy 2022-11-14 00:13:42 +08:00
parent 7cabc47886
commit 319ea4a679
3 changed files with 54 additions and 15 deletions

View File

@ -208,8 +208,52 @@ func GetArticleCount(c *gin.Context) {
resp.Msg = "OK"
}
// InsertDocHistory
func AddArticleHistory(c *gin.Context) {
rsp := RespBase{Msg: "FAIL", Status: 211}
type ReqUpdateArticle struct {
ID int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Author string `json:"author"`
Type int64 `json:"type"`
IsPublic int `json:"is_public"`
Father int `json:"father"`
Level int `json:"level"`
}
var req ReqUpdateArticle
defer func() {
c.JSON(200, rsp)
}()
er := c.BindJSON(&req)
if nil != er {
logs.Error(er.Error())
return
}
if req.Title == "" {
rsp.Msg = "title required"
return
}
e := model.InsertDocHistory(model.DocTree{
ID: (req.ID),
Type: int32(req.Type),
Title: req.Title,
Content: req.Content,
Author: req.Author,
Father: int32(req.Father),
Level: int32(req.Level),
},)
if(nil != e){
logs.Error(er.Error())
return
}
rsp.Msg = "OK"
rsp.Status = 0
}
func GetArticleHistory(c *gin.Context) {
resp := RespBase{Msg: "FAIL", Status: 211}
defer func() {

View File

@ -163,7 +163,7 @@ func main() {
api.PUT("/article", controller.AddArticle) // 添加文章
api.PUT("/article_tree", controller.AddArticleTree) // 添加文章
api.PUT("/article_tree_history", controller.AddArticleTree) // 添加文章
api.PUT("/article_tree_history", controller.AddArticleHistory) // 添加文章
api.PUT("/article_search", controller.SearchArticles) // 添加文章
api.GET("/article_type", controller.ArticlesType) //获取所有文章分类

View File

@ -167,16 +167,18 @@ func UpdateDoc(doc Doc) error {
logs.Error(e.Error())
return e
}
sql = fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`,
doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"))
_, er := db.GetMysqlClient().Query(sql)
if nil != er {
logs.Error(e.Error())
return e
}
// sql = fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`,
// doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"))
// _, er := db.GetMysqlClient().Query(sql)
// if nil != er {
// logs.Error(e.Error())
// return e
// }
return nil
}
// 添加文件版本。
func InsertDocHistory(doc DocTree) error{
sql := fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`,
doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"))
@ -202,13 +204,6 @@ func UpdateDocTree(doc DocTree) error {
logs.Error(e.Error())
return e
}
// sql = fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`,
// doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"))
// _, er := db.GetMysqlClient().Query(sql)
// if nil != er {
// logs.Error(e.Error())
// return e
// }
return nil
}