From 75d43137e0898911e1274fd11737f4c27b47c538 Mon Sep 17 00:00:00 2001 From: zenovio Date: Fri, 12 May 2023 01:12:18 +0800 Subject: [PATCH] Refactor: 2 helper functions added in article.py (get_article_by_id and get_all_articles) --- app/model/article.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/model/article.py b/app/model/article.py index a3b4bf7..15dfef2 100644 --- a/app/model/article.py +++ b/app/model/article.py @@ -32,3 +32,16 @@ def get_page_articles(num, size): x for x in Article.select().order_by(desc(Article.article_id)).page(num, size) ] + + +def get_article_by_id(article_id): + article_id &= 0xFFFFFFFF # max 32 bits + with db_session: + article = Article.select(article_id=article_id).first() + if article: + return article.to_dict() + + +def get_all_articles(): + with db_session: + return [art.to_dict() for art in Article.select()[:]] \ No newline at end of file