Refactor: 2 helper functions added in article.py (get_article_by_id and get_all_articles)

SOFTARCH2023S-ZENOVIO
Nze Avomo Zenovio Ndong 2023-05-12 01:12:18 +08:00
parent d9f6df7fbe
commit 75d43137e0
1 changed files with 13 additions and 0 deletions

View File

@ -32,3 +32,16 @@ def get_page_articles(num, size):
x x
for x in Article.select().order_by(desc(Article.article_id)).page(num, size) 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()[:]]