Skip to content

Commit

Permalink
Created API's for Get Open and Closed Issues (#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uttkarsh-raj authored May 15, 2024
1 parent 746db8b commit ddc78dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions website/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion website/tests_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={},
):
Expand Down

0 comments on commit ddc78dc

Please sign in to comment.