From 0fd96d592d7b23d1dd32e2ac18a868b43c9fd348 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 26 Jan 2023 11:41:20 +0530 Subject: [PATCH] feat: sub issue count endpoint (#186) --- apiserver/plane/api/urls.py | 6 +++ apiserver/plane/api/views/__init__.py | 1 + apiserver/plane/api/views/issue.py | 59 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index 050ce9c95..38d2b4013 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -65,6 +65,7 @@ from plane.api.views import ( TimeLineIssueViewSet, IssuePropertyViewSet, LabelViewSet, + SubIssuesEndpoint, ## End Issues # States StateViewSet, @@ -540,6 +541,11 @@ urlpatterns = [ UserWorkSpaceIssues.as_view(), name="workspace-issues", ), + path( + "workspaces//projects//issues//sub-issues/", + SubIssuesEndpoint.as_view(), + name="sub-issues", + ), ## End Issues ## Issue Activity path( diff --git a/apiserver/plane/api/views/__init__.py b/apiserver/plane/api/views/__init__.py index 1cadd95e6..933315277 100644 --- a/apiserver/plane/api/views/__init__.py +++ b/apiserver/plane/api/views/__init__.py @@ -51,6 +51,7 @@ from .issue import ( LabelViewSet, BulkDeleteIssuesEndpoint, UserWorkSpaceIssues, + SubIssuesEndpoint, ) from .auth_extended import ( diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 4212934bf..f716c2b11 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -525,3 +525,62 @@ class BulkDeleteIssuesEndpoint(BaseAPIView): {"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST, ) + + +class SubIssuesEndpoint(BaseAPIView): + + permission_classes = [ + ProjectEntityPermission, + ] + + def get(self, request, slug, project_id, issue_id): + try: + + sub_issues = ( + Issue.objects.filter( + parent_id=issue_id, workspace__slug=slug, project_id=project_id + ) + .select_related("project") + .select_related("workspace") + .select_related("state") + .select_related("parent") + .prefetch_related("assignees") + .prefetch_related("labels") + .prefetch_related( + Prefetch( + "blocked_issues", + queryset=IssueBlocker.objects.select_related( + "blocked_by", "block" + ), + ) + ) + .prefetch_related( + Prefetch( + "blocker_issues", + queryset=IssueBlocker.objects.select_related( + "block", "blocked_by" + ), + ) + ) + .prefetch_related( + Prefetch( + "issue_cycle", + queryset=CycleIssue.objects.select_related("cycle", "issue"), + ), + ) + .prefetch_related( + Prefetch( + "issue_module", + queryset=ModuleIssue.objects.select_related("module", "issue"), + ), + ) + ) + + serializer = IssueSerializer(sub_issues, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + except Exception as e: + capture_exception(e) + return Response( + {"error": "Something went wrong please try again later"}, + status=status.HTTP_400_BAD_REQUEST, + )