Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(mm): Allow Library Filtered by Project #723

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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