diff --git a/service/blog_service.py b/service/blog_service.py index ff891e8..188c708 100644 --- a/service/blog_service.py +++ b/service/blog_service.py @@ -93,12 +93,15 @@ def query_unapproved_blog(db: Session) -> List[BlogResponse]: BlogContent.content.label("content"), Blog.word_count.label("wordCount"), Blog.read_duration.label("readDuration"), + func.count(BlogVisit.id).label("visitCount"), Blog.is_approved.label("isApproved"), Blog.create_time.label("createTime"), Blog.update_time.label("updateTime") ).where(Blog.is_approved == 0) .outerjoin(BlogCategory, Blog.category_id == BlogCategory.id) .outerjoin(BlogContent, Blog.content_id == BlogContent.id)) + .outerjoin(BlogVisit, Blog.id == BlogVisit.blog_id) + .group_by(Blog.id) .order_by(desc(Blog.update_time))) results = db.execute(stmt).fetchall()