mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-20 03:38:28 +00:00
add club search api filters
This commit is contained in:
33
club/api.py
33
club/api.py
@@ -1,4 +1,4 @@
|
|||||||
from typing import Annotated
|
from typing import Annotated, Optional
|
||||||
|
|
||||||
from annotated_types import MinLen
|
from annotated_types import MinLen
|
||||||
from django.db.models import Prefetch
|
from django.db.models import Prefetch
|
||||||
@@ -23,8 +23,35 @@ class ClubController(ControllerBase):
|
|||||||
url_name="search_club",
|
url_name="search_club",
|
||||||
)
|
)
|
||||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
@paginate(PageNumberPaginationExtra, page_size=50)
|
||||||
def search_club(self, search: Annotated[str, MinLen(1)]):
|
def search_club(
|
||||||
return Club.objects.filter(name__icontains=search).values()
|
self,
|
||||||
|
search: Annotated[Optional[str], MinLen(1), "filter by name"] = None,
|
||||||
|
club_id: Annotated[Optional[int], "filter by club id"] = None,
|
||||||
|
excluded_ids: Annotated[
|
||||||
|
Optional[list[int]], "filter by excluded club ids"
|
||||||
|
] = None,
|
||||||
|
is_active: Annotated[Optional[bool], "filter by club activity"] = None,
|
||||||
|
parent_id: Annotated[Optional[int], "filter by parent id"] = None,
|
||||||
|
parent_name: Annotated[
|
||||||
|
Optional[str], MinLen(1), "filter by parent name"
|
||||||
|
] = None,
|
||||||
|
):
|
||||||
|
queryset = Club.objects.all()
|
||||||
|
|
||||||
|
if search:
|
||||||
|
queryset = queryset.filter(name__icontains=search)
|
||||||
|
if club_id:
|
||||||
|
queryset = queryset.filter(id=club_id)
|
||||||
|
if is_active:
|
||||||
|
queryset = queryset.filter(is_active=is_active)
|
||||||
|
if parent_name:
|
||||||
|
queryset = queryset.filter(parent__name__icontains=parent_name)
|
||||||
|
if parent_id:
|
||||||
|
queryset = queryset.filter(parent_id=parent_id)
|
||||||
|
if excluded_ids:
|
||||||
|
queryset = queryset.exclude(id__in=excluded_ids)
|
||||||
|
|
||||||
|
return queryset.values()
|
||||||
|
|
||||||
@route.get(
|
@route.get(
|
||||||
"/{int:club_id}",
|
"/{int:club_id}",
|
||||||
|
Reference in New Issue
Block a user