Filter out old events when fetching them (#23)

* Update events.py

Update events.py to only display events less than an hour past their start time.

* Update events.py

* Update backend-flask/events.py

Co-authored-by: HumanoidSandvichDispenser <25856867+HumanoidSandvichDispenser@users.noreply.github.com>

* Update backend-flask/events.py

Co-authored-by: HumanoidSandvichDispenser <25856867+HumanoidSandvichDispenser@users.noreply.github.com>

---------

Co-authored-by: HumanoidSandvichDispenser <25856867+HumanoidSandvichDispenser@users.noreply.github.com>
master
Cyb3rL1z4rd 2025-05-21 12:58:38 -04:00 committed by GitHub
parent f70a5d69e3
commit aefb9c30f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -6,7 +6,7 @@
# Distributed under terms of the MIT license. # Distributed under terms of the MIT license.
from datetime import datetime from datetime import datetime, timedelta, timezone
from typing import Optional from typing import Optional
from flask import Blueprint, abort, make_response from flask import Blueprint, abort, make_response
@ -52,13 +52,16 @@ def get_event(event_id: int):
@requires_authentication @requires_authentication
@requires_team_membership() @requires_team_membership()
def get_team_events(player_team: PlayerTeam, team_id: int, **_): def get_team_events(player_team: PlayerTeam, team_id: int, **_):
time_now = datetime.now(timezone.utc)
rows = db.session.query( rows = db.session.query(
Event, PlayerEvent Event, PlayerEvent
).outerjoin( ).outerjoin(
PlayerEvent, PlayerEvent,
(PlayerEvent.event_id == Event.id) & (PlayerEvent.player_id == player_team.player_id) (PlayerEvent.event_id == Event.id) & (PlayerEvent.player_id == player_team.player_id)
).where( ).where(
Event.team_id == team_id Event.team_id == team_id,
Event.start_time >= (time_now - timedelta(hours=1))
).order_by( ).order_by(
Event.start_time Event.start_time
).all() ).all()