From b4e37a71d06de246ec0dd0bb283e249c05f795bc Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 10 Nov 2024 18:42:13 +0100 Subject: [PATCH] add current_time in list all events --- app/routers/events.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/routers/events.py b/app/routers/events.py index 66ac51c..0decbc3 100644 --- a/app/routers/events.py +++ b/app/routers/events.py @@ -22,6 +22,19 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per listEvents = [] event_repository = events.EventRepository(database=database.database) object_search = {} + if current_datetime is not None: + object_search ={ + "$or": [{"start_date": {"$gte": current_datetime}}, # Upcoming events + {"$and": [ # Ongoing events + {"start_date": {"$lte": current_datetime}}, # Already started + {"$or": [ + {"end_date": {"$gte": current_datetime}}, # End date in the future + {"end_date": None} # No end date set + ]} + ]} + ] + } + if status is not 1: object_search = {"status":{"$eq": status}} if current_datetime is not None: