From 18059a22febfd979b6d30c1e31f09c90184f57d4 Mon Sep 17 00:00:00 2001 From: William Putra Intan <61998484+williamputraintan@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:45:41 +1100 Subject: [PATCH] Feat(mm): Allow Library Filtered by Project (#723) --- .../metadata-manager/app/viewsets/library.py | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/workload/stateless/stacks/metadata-manager/app/viewsets/library.py b/lib/workload/stateless/stacks/metadata-manager/app/viewsets/library.py index c74d893ca..c315154fb 100644 --- a/lib/workload/stateless/stacks/metadata-manager/app/viewsets/library.py +++ b/lib/workload/stateless/stacks/metadata-manager/app/viewsets/library.py @@ -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 @@ -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)