Merge pull request 'add current_time in list all events' (#27) from feature/listEventDate into master

Reviewed-on: #27
This commit is contained in:
v4l3n71n 2024-11-10 18:45:39 +01:00
commit 36ae3504b8

View File

@ -22,6 +22,19 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
listEvents = [] listEvents = []
event_repository = events.EventRepository(database=database.database) event_repository = events.EventRepository(database=database.database)
object_search = {} 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: if status is not 1:
object_search = {"status":{"$eq": status}} object_search = {"status":{"$eq": status}}
if current_datetime is not None: if current_datetime is not None: