From ddc78dc622f62cfc1fe6578573380671231e29cc Mon Sep 17 00:00:00 2001 From: Uttkarsh-raj <106571927+Uttkarsh-raj@users.noreply.github.com> Date: Wed, 15 May 2024 23:01:18 +0530 Subject: [PATCH] Created API's for Get Open and Closed Issues (#2090) --- website/api/views.py | 17 ++++++++++++----- website/tests_urls.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/website/api/views.py b/website/api/views.py index 8fc7048fb..804ba52c3 100644 --- a/website/api/views.py +++ b/website/api/views.py @@ -125,10 +125,20 @@ class IssueViewSet(viewsets.ModelViewSet): def get_queryset(self): anonymous_user = self.request.user.is_anonymous user_id = self.request.user.id + status = self.request.GET.get("status") + domain_url = self.request.GET.get("domain") + if anonymous_user: - return Issue.objects.exclude(Q(is_hidden=True)) + queryset = Issue.objects.exclude(Q(is_hidden=True)) else: - return Issue.objects.exclude(Q(is_hidden=True) & ~Q(user_id=user_id)) + queryset = Issue.objects.exclude(Q(is_hidden=True) & ~Q(user_id=user_id)) + + if status: + queryset = queryset.filter(status=status) + if domain_url: + queryset = queryset.filter(domain__url=domain_url) + + return queryset def get_issue_info(self, request, issue): if issue is None: @@ -166,15 +176,12 @@ def get_issue_info(self, request, issue): def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) - issues = [] page = self.paginate_queryset(queryset) if page is None: return Response(issues) - for issue in page: issues.append(self.get_issue_info(request, issue)) - return self.get_paginated_response(issues) def retrieve(self, request, pk, *args, **kwargs): diff --git a/website/tests_urls.py b/website/tests_urls.py index 9f37a4491..43e65b86d 100644 --- a/website/tests_urls.py +++ b/website/tests_urls.py @@ -33,7 +33,7 @@ def tearDownClass(cls): def test_responses( self, - allowed_http_codes=[200, 302, 405, 401], + allowed_http_codes=[200, 302, 405, 401, 404], credentials={}, default_kwargs={}, ):