diff --git a/database/repositories/infringements.py b/database/repositories/infringements.py index a4724d3..3b83866 100644 --- a/database/repositories/infringements.py +++ b/database/repositories/infringements.py @@ -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) \