From f3e54bd8669f9f1cbed918ad6ea6b38eedc1ea6e Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Thu, 26 Mar 2020 20:15:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=98=AF=E5=90=A6=E5=85=AC?= =?UTF-8?q?=E5=BC=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 4 ++++ model/blog.go | 9 ++++++--- model/hardware.go | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 90e3a73..2ee2e03 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -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{ diff --git a/model/blog.go b/model/blog.go index 2329a37..67fc001 100644 --- a/model/blog.go +++ b/model/blog.go @@ -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 , + %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()) diff --git a/model/hardware.go b/model/hardware.go index 5b745f8..77f035a 100644 --- a/model/hardware.go +++ b/model/hardware.go @@ -54,3 +54,4 @@ func GetHardwares(limit int,size int) ([]Hardware,error){ } return ret,nil } +