添加公开文章类型相关逻辑
parent
73421d20fd
commit
1867f78730
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue