Compare commits

..

15 Commits
1.0.9 ... 1.2.5

Author SHA1 Message Date
9574ce5aeb Merge pull request 'feature/search' (#24) from feature/search into master
Reviewed-on: #24
2024-11-04 23:06:10 +01:00
115a5acb6f add another object_search 2024-11-04 22:58:51 +01:00
4c2d4646ce add lat and long as parameter 2024-11-04 22:57:53 +01:00
4f0cda831f Merge pull request 'add event set status to 1' (#23) from feature/search into master
Reviewed-on: #23
2024-10-23 23:37:50 +02:00
360ac8771a add event set status to 1 2024-10-23 23:36:09 +02:00
df4a2bead6 Merge pull request 'fix object_search' (#22) from feature/search into master
Reviewed-on: #22
2024-10-23 23:22:59 +02:00
a1e135a03e fix object_search 2024-10-23 23:22:05 +02:00
8397d84ec5 Merge pull request 'fix endpoint search' (#21) from feature/search into master
Reviewed-on: #21
2024-10-23 23:08:46 +02:00
9108e15555 fix endpoint search 2024-10-23 23:07:28 +02:00
fcb11dd0d8 Merge pull request 'list events only enabled' (#20) from feature/search into master
Reviewed-on: #20
2024-10-23 23:02:24 +02:00
3f4173863c list events only enabled 2024-10-23 22:58:17 +02:00
6781789012 Merge pull request 'add search' (#19) from feature/search into master
Reviewed-on: #19
2024-10-23 22:04:08 +02:00
436e6d68dd add search 2024-10-23 21:44:33 +02:00
2bbb3a0a95 Merge pull request 'add search' (#18) from feature/category into master
Reviewed-on: #18
2024-10-21 20:18:01 +02:00
d91e561561 add search 2024-10-20 20:56:24 +02:00

View File

@@ -11,7 +11,7 @@ router = APIRouter()
@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 | 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):
if limit < 1 or skip < 0 or limit < skip:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@@ -21,17 +21,18 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
listEvents = []
event_repository = events.EventRepository(database=database.database)
object_search = {}
if status is not None:
if status is not 1:
object_search = {"status":{"$eq": status}}
if tags is not None:
object_search = {"$and":[{"tags":{"$eq": tags}}, {"status":{"$eq":status}}]}
if organizers is not None:
object_search = {"$and":[{"organizers":{"$eq": organizers}}, {"status":{"$eq":status}}]}
if id_event is not None:
eventid = ObjectId(id_event)
object_search = {"id": {"$regex": userid}}
if status is not None:
object_search = {"$and":[{"id":{"$regex": eventid}}, {"status":{"$eq":status}}]}
object_search = {"$and":[{"id":{"$regex": eventid}}, {"status":{"$eq":status}}]}
if name is not None:
object_search = {"name": {"$regex": name}}
if status is not None:
object_search = {"$and":[{"name":{"$regex": name}}, {"status":{"$eq":status}}]}
object_search = {"$and":[{"name":{"$regex": name}}, {"status":{"$eq":status}}]}
for event_index in event_repository.find_by(object_search, limit=limit, skip=skip):
@@ -40,6 +41,80 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
return listEvents
@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):
if limit < 1 or skip < 0 or limit < skip:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="skip should be greater than 0 and limit should be greater than 1. Limit should be greater than skip"
)
limit = limit + skip
listEvents = []
event_repository = events.EventRepository(database=database.database)
object_search = {}
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 = {
"$and": [
{"status": {"$eq": status}},
{
"latitude": {"$gte": min_lat}, # Minimum latitude
},
{
"latitude": {"$lte": max_lat}, # Maximum latitude
},
{
"longitude": {"$gte": min_lon}, # Minimum longitude
},
{
"longitude": {"$lte": max_lon}, # Maximum longitude
}
]
}
if item is not None:
object_search = {
"$and": [
{
"$or": [
{"name": {"$regex": item}},
{"tags": {"$regex": item}},
{"organizers": {"$regex": item}}
]
},
{"status": {"$eq": status}}
]
}
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 = {
"$and": [
{
"$or": [
{"name": {"$regex": item}},
{"tags": {"$regex": item}},
{"organizers": {"$regex": item}}
]
},
{"status": {"$eq": status}},
{
"latitude": {"$gte": min_lat}, # Minimum latitude
},
{
"latitude": {"$lte": max_lat}, # Maximum latitude
},
{
"longitude": {"$gte": min_lon}, # Minimum longitude
},
{
"longitude": {"$lte": max_lon}, # Maximum longitude
}
]
}
for event_index in event_repository.find_by(object_search, limit=limit, skip=skip):
event = events.EventOut(id=event_index.id, tags=event_index.tags, imgUrl=event_index.imgUrl, name=event_index.name, description=event_index.description, place=event_index.place, zip_code=event_index.zip_code, city=event_index.city, country=event_index.country, status=event_index.status, start_date=event_index.start_date, end_date=event_index.end_date)
listEvents.append(event)
return listEvents
@router.get("/events/me",tags=["events"])
async def read_users_me(current_user: Annotated[users.User, Depends(users_token.get_current_active_user)], authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))]):
event_repository = events.EventRepository(database=database.database)
@@ -171,6 +246,7 @@ async def update_events(authorize: Annotated[bool, Depends(permissions_checker.P
event.longitude = eventSingle.longitude
event.imgUrl = eventSingle.imgUrl
event.tags = eventSingle.tags
event.status = 1
event.created_at = datetime.today()
event_repository.save(event)
content = {"message": "event is created"}