Skip to content

Commit

Permalink
Feat(mm): Allow Library Filtered by Project (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamputraintan authored Nov 27, 2024
1 parent 446eb0f commit 18059a2
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from drf_spectacular.utils import extend_schema
from drf_spectacular.utils import extend_schema, OpenApiParameter
from rest_framework.decorators import action

from app.models import Library
Expand All @@ -17,21 +17,38 @@ def get_queryset(self):
qs = self.queryset
query_params = self.get_query_params()

coverage__lte = query_params.get("coverage__lte", None)
coverage__lte = query_params.get("coverage[lte]", None)
if coverage__lte:
query_params.pop("coverage__lte")
query_params.pop("coverage[lte]")
qs = qs.filter(coverage__lte=coverage__lte)

coverage__gte = query_params.get("coverage__gte", None)
coverage__gte = query_params.get("coverage[gte]", None)
if coverage__gte:
query_params.pop("coverage__gte")
query_params.pop("coverage[gte]")
qs = qs.filter(coverage__gte=coverage__gte)

project_id_list = query_params.getlist("project_id", None)
if project_id_list:
query_params.pop("project_id")
qs = qs.filter(project_set__project_id__in=project_id_list)

# Continue filtering by the keys inside the library model
return Library.objects.get_by_keyword(qs, **query_params)

@extend_schema(parameters=[
LibrarySerializer
LibrarySerializer,
OpenApiParameter(name='coverage[lte]',
description="Filter based on 'coverage' that is less than or equal to the given value.",
required=False,
type=float),
OpenApiParameter(name='coverage[gte]',
description="Filter based on 'coverage' that is greater than or equal to the given value.",
required=False,
type=float),
OpenApiParameter(name='project_id',
description="Filter where the associated the project has the given 'project_id'.",
required=False,
type=float),
])
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)
Expand Down

0 comments on commit 18059a2

Please sign in to comment.