添加是否公开判断

master
a7458969 2020-03-26 20:15:04 +08:00
parent 6baf8c4546
commit f3e54bd866
3 changed files with 11 additions and 3 deletions

View File

@ -135,6 +135,7 @@ func UpdateArtilce(c *gin.Context) {
Content string `json:"content"`
author string `json:"author"`
Type int64 `json:"type"`
IsPublic int `json:"is_public"`
}
var req ReqUpdateArticle
defer func() {
@ -156,6 +157,7 @@ func UpdateArtilce(c *gin.Context) {
Content:req.Content,
Author:req.author,
ID:req.Id,
IsPublic:req.IsPublic,
},
)
if nil != e{
@ -174,6 +176,7 @@ func AddArticle(c *gin.Context) {
Content string `json:"content"`
author string `json:"author"`
Type int64 `json:"type"`
Ispublic int `json:"ispublic"`
}
var req ReqAddArticle
defer func() {
@ -194,6 +197,7 @@ func AddArticle(c *gin.Context) {
Title:req.Title,
Content:req.Content,
Author:req.author,
IsPublic:req.Ispublic,
},
)
if nil != e{

View File

@ -14,6 +14,7 @@ type Doc struct {
Type int64 `sql:"type" json:"type"`
Content string `sql:"content" json:"content"`
Author string `sql:"author" json:"author"`
IsPublic int `sql:"is_public" json:"is_public"`
}
type ArticleType struct {
@ -35,15 +36,17 @@ func GetArticlesType() []ArticleType {
}
func CreateDoc(doc Doc) error {
sql := fmt.Sprintf(`INSERT INTO doc ( doc.title, doc.content, doc.author, doc.type ) SELECT
sql := fmt.Sprintf(`INSERT INTO doc ( doc.title, doc.content, doc.author, doc.type,doc.is_public) SELECT
'%s',
'%s',
'%s',
%d ,
%d
FROM
DUAL
WHERE
NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1), doc.Author, doc.Type,doc.Title)
NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1),
doc.Author, doc.Type,doc.IsPublic,doc.Title)
_, e := db.GetMysqlClient().Query(sql)
if nil != e {
logs.Error(e.Error())

View File

@ -54,3 +54,4 @@ func GetHardwares(limit int,size int) ([]Hardware,error){
}
return ret,nil
}