package article import ( "nCovTrack-Backend/models" ) //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 } //ListAllArticles list all articles, will show the articles not published of the user // 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{}{} } return article } //SaveArticle save the articles func SaveArticle(article map[string]interface{}) (ok bool) { models.BeforeSave(article, -1) ok, rows := models.Upsert[models.BackArticle](article) return ok && rows != 0 } //DeleteArticle delete article by id func DeleteArticle(id int) (ok bool) { ok, rowsAffected := models.DeleteById[models.BackArticle](id) return ok && rowsAffected != 0 } //GetArticleById get an article func GetArticleById(id int) map[string]interface{} { return models.Get[models.BackArticle]([]map[string]interface{}{{"id": id}}) } //PublishArticle publish an article func PublishArticle(id int) (ok bool) { colMap := map[string]interface{}{"id": id, "is_publish": 1} ok, rowsAffected := models.Upsert[models.BackArticle](colMap) return ok && rowsAffected != 0 }