Merge pull request 'add selected date' (#29) from feature/searchByDate into master
Reviewed-on: #29
This commit is contained in:
commit
beff787801
@ -12,7 +12,7 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/events", tags=["events"], response_model=list[events.EventOut])
|
@router.get("/events", tags=["events"], response_model=list[events.EventOut])
|
||||||
async def read_events(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))], skip: int = 0, limit: int = 20, id_event: str | None = None, name: str | None = None, status: int = 1, tags: str | None = None, organizers: str | None = None, current_datetime: datetime | None = None, date_event: datetime |None = None):
|
async def read_events(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))], skip: int = 0, limit: int = 20, id_event: str | None = None, name: str | None = None, status: int = 1, tags: str | None = None, organizers: str | None = None, current_datetime: datetime | None = None, date_event: datetime |None = None, start_date: datetime | None = None, end_date: datetime | None = None):
|
||||||
if limit < 1 or skip < 0 or limit < skip:
|
if limit < 1 or skip < 0 or limit < skip:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
@ -22,9 +22,15 @@ 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 = {}
|
||||||
|
date_selected: bool = False
|
||||||
if date_event is not None:
|
if date_event is not None:
|
||||||
start_of_day = datetime.combine(date_event, datetime.min.time()) # 2024-11-23 00:00:00
|
start_of_day = datetime.combine(date_event, datetime.min.time()) # 2024-11-23 00:00:00
|
||||||
end_of_day = datetime.combine(date_event, datetime.max.time())
|
end_of_day = datetime.combine(date_event, datetime.max.time())
|
||||||
|
date_selected = True
|
||||||
|
if start_date is not None and end_date is not None:
|
||||||
|
start_of_day = datetime.combine(start_date, datetime.min.time()) # 2024-11-23 00:00:00
|
||||||
|
end_of_day = datetime.combine(end_date, datetime.max.time())
|
||||||
|
date_selected = True
|
||||||
if current_datetime is not None:
|
if current_datetime is not None:
|
||||||
object_search ={
|
object_search ={
|
||||||
"$or": [{"start_date": {"$gte": current_datetime}}, # Upcoming events
|
"$or": [{"start_date": {"$gte": current_datetime}}, # Upcoming events
|
||||||
@ -37,7 +43,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
]}
|
]}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search ={
|
object_search ={
|
||||||
"$and": [{"start_date": {"$gte": start_of_day}},
|
"$and": [{"start_date": {"$gte": start_of_day}},
|
||||||
{"start_date": {"$lte": end_of_day}} # Upcoming events
|
{"start_date": {"$lte": end_of_day}} # Upcoming events
|
||||||
@ -60,7 +66,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = { "$and": [ {"status":{"$eq": status}},
|
object_search = { "$and": [ {"status":{"$eq": status}},
|
||||||
{"start_date": {"$gte": start_of_day}},
|
{"start_date": {"$gte": start_of_day}},
|
||||||
{"start_date": {"$lte": end_of_day}}
|
{"start_date": {"$lte": end_of_day}}
|
||||||
@ -84,7 +90,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {"$and":[{"tags":{"$eq": tags}},
|
object_search = {"$and":[{"tags":{"$eq": tags}},
|
||||||
{"status":{"$eq":status}},
|
{"status":{"$eq":status}},
|
||||||
{"start_date": {"$gte": start_of_day}},
|
{"start_date": {"$gte": start_of_day}},
|
||||||
@ -109,7 +115,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {"$and":[{"organizers":{"$eq": organizers}},
|
object_search = {"$and":[{"organizers":{"$eq": organizers}},
|
||||||
{"status":{"$eq":status}},
|
{"status":{"$eq":status}},
|
||||||
{"start_date": {"$gte": start_of_day}},
|
{"start_date": {"$gte": start_of_day}},
|
||||||
@ -134,7 +140,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {"$and":[{"id":{"$regex": eventid}},
|
object_search = {"$and":[{"id":{"$regex": eventid}},
|
||||||
{"status":{"$eq":status}},
|
{"status":{"$eq":status}},
|
||||||
{"start_date": {"$gte": start_of_day}},
|
{"start_date": {"$gte": start_of_day}},
|
||||||
@ -158,7 +164,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {"$and":[{"name":{"$regex": name}},
|
object_search = {"$and":[{"name":{"$regex": name}},
|
||||||
{"status":{"$eq":status}},
|
{"status":{"$eq":status}},
|
||||||
{"start_date": {"$gte": start_of_day}},
|
{"start_date": {"$gte": start_of_day}},
|
||||||
@ -172,7 +178,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/events/search", tags=["events"], response_model=list[events.EventOut])
|
@router.get("/events/search", tags=["events"], response_model=list[events.EventOut])
|
||||||
async def search_events(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))], skip: int = 0, limit: int = 20, item: str | None = None, status: int = 1, min_lat: float | None = None, max_lat: float | None = None, min_lon: float | None = None, max_lon: float | None = None, current_datetime: datetime | None = None, date_event: datetime | None = None):
|
async def search_events(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))], skip: int = 0, limit: int = 20, item: str | None = None, status: int = 1, min_lat: float | None = None, max_lat: float | None = None, min_lon: float | None = None, max_lon: float | None = None, current_datetime: datetime | None = None, date_event: datetime | None = None, start_date: datetime | None = None, end_date: datetime | None = None):
|
||||||
if limit < 1 or skip < 0 or limit < skip:
|
if limit < 1 or skip < 0 or limit < skip:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
@ -182,9 +188,15 @@ async def search_events(authorize: Annotated[bool, Depends(permissions_checker.P
|
|||||||
listEvents = []
|
listEvents = []
|
||||||
event_repository = events.EventRepository(database=database.database)
|
event_repository = events.EventRepository(database=database.database)
|
||||||
object_search = {}
|
object_search = {}
|
||||||
|
date_selected: bool = False
|
||||||
if date_event is not None:
|
if date_event is not None:
|
||||||
start_of_day = datetime.combine(date_event, datetime.min.time()) # 2024-11-23 00:00:00
|
start_of_day = datetime.combine(date_event, datetime.min.time()) # 2024-11-23 00:00:00
|
||||||
end_of_day = datetime.combine(date_event, datetime.max.time())
|
end_of_day = datetime.combine(date_event, datetime.max.time())
|
||||||
|
date_selected = True
|
||||||
|
if start_date is not None and end_date is not None:
|
||||||
|
start_of_day = datetime.combine(start_date, datetime.min.time()) # 2024-11-23 00:00:00
|
||||||
|
end_of_day = datetime.combine(dateend_date_event, datetime.max.time())
|
||||||
|
date_selected = True
|
||||||
if min_lat is not None and max_lat is not None and min_lon is not None and max_lon is not None:
|
if min_lat is not None and max_lat is not None and min_lon is not None and max_lon is not None:
|
||||||
object_search = {
|
object_search = {
|
||||||
"$and": [
|
"$and": [
|
||||||
@ -233,7 +245,7 @@ async def search_events(authorize: Annotated[bool, Depends(permissions_checker.P
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {
|
object_search = {
|
||||||
"$and": [
|
"$and": [
|
||||||
{"status": {"$eq": status}},
|
{"status": {"$eq": status}},
|
||||||
@ -291,7 +303,7 @@ async def search_events(authorize: Annotated[bool, Depends(permissions_checker.P
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {
|
object_search = {
|
||||||
"$and": [
|
"$and": [
|
||||||
{
|
{
|
||||||
@ -368,7 +380,7 @@ async def search_events(authorize: Annotated[bool, Depends(permissions_checker.P
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
if date_event is not None:
|
if date_selected is True:
|
||||||
object_search = {
|
object_search = {
|
||||||
"$and": [
|
"$and": [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user