From 1867f787301b73a142ef1d347fb032d8348285ef Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Tue, 28 Apr 2020 12:29:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=AC=E5=BC=80=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E7=B1=BB=E5=9E=8B=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 11f7e2a..1751b3d 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -24,6 +24,7 @@ func GetPageParaFromQuery(c *gin.Context) (int,int){ } return iLmit,iOffset } + func GetArticles(c *gin.Context) { type ReqArticles struct { Name string `json:"name"` @@ -41,20 +42,49 @@ func GetArticles(c *gin.Context) { } article := []model.Doc{} limit,offset := GetPageParaFromQuery(c) + public := c.Query("is_public") + var sql string if req.Name != ""{ if req.Type == 110{ - sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' limit %d offset %d ",req.Name,limit,offset*limit) + is_public := 0 + if public == "true"{ + is_public = 0 + }else{ + is_public = 1 + } + sql = "select * from doc where doc.title like '%%%s%%' and is_public = %d limit %d offset %d " + sql = fmt.Sprintf(sql,is_public) + }else{ - sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d limit %d offset %d ",req.Name,req.Type,limit,offset*limit) + is_public := 0 + if public == "true"{ + is_public = 0 + }else{ + is_public = 1 + } + sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d and is_public = %d limit %d offset %d ",is_public,req.Name,req.Type,limit,offset*limit) } }else{ if req.Type == 110{ - sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc " + - "limit %d offset %d",limit,offset) + is_public := 0 + if public == "true"{ + is_public = 1 + }else{ + is_public = 0 + } + sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc where is_public = %d " + + "limit %d offset %d",is_public,limit,offset) }else{ - sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d " + - "limit %d offset %d",req.Type,limit,offset) + is_public := 0 + if public == "true"{ + is_public = 0 + }else{ + is_public = 1 + } + sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d and is_public = %d" + + "limit %d offset %d",is_public,req.Type,limit,offset) + } } e = db.GetMysqlClient().Query2(sql,&article)