Skip to content

Commit

Permalink
filter appllication by status
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheo committed Oct 9, 2024
1 parent f01709e commit 9abb172
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pots/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class PotApplicationsAPI(APIView, CustomSizePageNumberPagination):
@extend_schema(
parameters=[
OpenApiParameter("pot_id", str, OpenApiParameter.PATH),
OpenApiParameter(
"status",
str,
OpenApiParameter.QUERY,
required=False,
description="Filter by application status",
),
*pagination_parameters,
],
responses={
Expand Down Expand Up @@ -172,6 +179,13 @@ def get(self, request: Request, *args, **kwargs):
return Response({"message": f"Pot with ID {pot_id} not found."}, status=404)

applications = pot.applications.all()
status_param = request.query_params.get("status")
if status_param:
if status_param not in PotApplicationStatus.values:
return Response(
{"message": f"Invalid status value: {status_param}"}, status=400
)
applications = applications.filter(status=status_param)
results = self.paginate_queryset(applications, request, view=self)
serializer = PotApplicationSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
Expand Down

0 comments on commit 9abb172

Please sign in to comment.