fix: add role limit

This commit is contained in:
fallen-angle
2022-04-27 22:08:02 +08:00
parent fc347a4140
commit 22cb5ec61f
19 changed files with 274 additions and 77 deletions

View File

@@ -1,26 +1,40 @@
package article
import (
"nCovTrack-Backend/global"
"nCovTrack-Backend/models"
"strconv"
)
//ListPublishedArticles list the articles published, use to show the articles to all people
func ListPublishedArticles() *[]map[string]interface{} {
article := models.ListField[models.BackArticle]([]map[string]interface{}{{"is_publish": 0}}, true, "content")
if *article == nil {
article = &[]map[string]interface{}{}
}
return article
func ListPublishedArticles() *[]models.ListArtile {
return listArticles(1, 0)
}
//ListAllArticles list all articles, will show the articles not published of the user
func ListPublishedArticlesByUser(id int) *[]models.ListArtile {
return listArticles(1, id)
}
//ListAllArticles list all articles(without not published)
// TODO: need only show the user's not published article
func ListAllArticles() *[]map[string]interface{} {
article := models.ListField[models.BackArticle]([]map[string]interface{}{{}}, true, "content")
if *article == nil {
article = &[]map[string]interface{}{}
func ListNotPublishedArticlesByUser(id int) *[]models.ListArtile {
return listArticles(0, id)
}
func listArticles(isPublish int, createUser int) *[]models.ListArtile {
queryStr := "back_article.is_delete = 0 AND is_publish = " + strconv.Itoa(isPublish)
if createUser != 0 {
queryStr += " AND create_user = " + strconv.Itoa(createUser)
}
return article
var res []models.ListArtile
global.Db.Table("back_article").
Select("back_user.username, back_article.*").
Joins("join back_user on back_article.create_user=back_user.id").
Where(queryStr).Find(&res)
if res == nil {
res = []models.ListArtile{}
}
return &res
}
//SaveArticle save the articles