Skip to content

Commit

Permalink
Add forums repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekuruu committed Mar 26, 2024
1 parent dc905eb commit 32495af
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions database/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
comments,
clients,
ratings,
forums,
topics,
groups,
scores,
logins,
posts,
names,
stats,
plays,
Expand Down
52 changes: 52 additions & 0 deletions database/repositories/forums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

from __future__ import annotations

from app.common.database.objects import DBForum, DBForumPost, DBForumTopic
from sqlalchemy.orm import Session
from typing import List

from .wrapper import session_wrapper

@session_wrapper
def fetch_by_id(forum_id: int, session: Session | None = None) -> DBForum | None:
return session.query(DBForum) \
.filter(DBForum.id == forum_id) \
.first()

@session_wrapper
def fetch_by_name(name: str, session: Session | None = None) -> DBForum | None:
return session.query(DBForum) \
.filter(DBForum.name == name) \
.first()

@session_wrapper
def fetch_all(session: Session | None = None) -> List[DBForum]:
return session.query(DBForum) \
.filter(DBForum.hidden == False) \
.all()

@session_wrapper
def fetch_main_forums(session: Session | None = None) -> List[DBForum]:
return session.query(DBForum) \
.filter(DBForum.parent_id == None) \
.filter(DBForum.hidden == False) \
.all()

@session_wrapper
def fetch_sub_forums(parent_id: int, session: Session | None = None) -> List[DBForum]:
return session.query(DBForum) \
.filter(DBForum.parent_id == parent_id) \
.filter(DBForum.hidden == False) \
.all()

@session_wrapper
def fetch_post_count(forum_id: int, session: Session | None = None) -> int:
return session.query(DBForumPost) \
.filter(DBForumPost.forum_id == forum_id) \
.count()

@session_wrapper
def fetch_topic_count(forum_id: int, session: Session | None = None) -> int:
return session.query(DBForumTopic) \
.filter(DBForumTopic.forum_id == forum_id) \
.count()

0 comments on commit 32495af

Please sign in to comment.