Skip to content

Commit

Permalink
Add infringements.fetch_recent_until query
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekuruu committed Dec 18, 2023
1 parent 1ca9662 commit bae56df
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions database/repositories/infringements.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def fetch_recent_by_action(user_id: int, action: int, session: Session | None =
.order_by(DBInfringement.id.desc()) \
.first()

@session_wrapper
def fetch_recent_until(
user_id: int,
until: timedelta = timedelta(days=30),
session: Session | None = None
) -> List[DBInfringement]:
return session.query(DBInfringement) \
.filter(DBInfringement.user_id == user_id) \
.filter(DBInfringement.time > (datetime.now() - until)) \
.order_by(DBInfringement.id.desc()) \
.all()

@session_wrapper
def fetch_all(user_id: int, session: Session | None = None) -> List[DBInfringement]:
return session.query(DBInfringement) \
Expand Down

0 comments on commit bae56df

Please sign in to comment.