From 464c0f2308ed171ce252b0e453ecad17c674f106 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:25:47 +0530 Subject: [PATCH] chore: add assignee avatar and minor refactor on cycles list and retrieve endpoint (#1320) --- apiserver/plane/api/views/cycle.py | 41 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index f959f62b5..0dd5d67d0 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -1,6 +1,5 @@ # Python imports import json -from datetime import datetime, timedelta # Django imports from django.db import IntegrityError @@ -15,7 +14,6 @@ from django.db.models import ( Prefetch, Sum, ) -from django.db.models.functions import TruncDate from django.core import serializers from django.utils import timezone from django.utils.decorators import method_decorator @@ -163,14 +161,9 @@ class CycleViewSet(BaseViewSet): ) def list(self, request, slug, project_id): - # try: + try: queryset = self.get_queryset() - cycle_view = request.GET.get("cycle_view", False) - if not cycle_view: - return Response( - {"error": "Cycle View parameter is required"}, - status=status.HTTP_400_BAD_REQUEST, - ) + cycle_view = request.GET.get("cycle_view", "all") # All Cycles if cycle_view == "all": @@ -197,7 +190,8 @@ class CycleViewSet(BaseViewSet): .annotate(first_name=F("assignees__first_name")) .annotate(last_name=F("assignees__last_name")) .annotate(assignee_id=F("assignees__id")) - .values("first_name", "last_name", "assignee_id") + .annotate(avatar=F("assignees__avatar")) + .values("first_name", "last_name", "assignee_id", "avatar") .annotate(total_issues=Count("assignee_id")) .annotate( completed_issues=Count( @@ -252,9 +246,7 @@ class CycleViewSet(BaseViewSet): cycle_id=data[0]["id"], ) - return Response( - data, status=status.HTTP_200_OK - ) + return Response(data, status=status.HTTP_200_OK) # Upcoming Cycles if cycle_view == "upcoming": @@ -293,12 +285,13 @@ class CycleViewSet(BaseViewSet): return Response( {"error": "No matching view found"}, status=status.HTTP_400_BAD_REQUEST ) - # except Exception as e: - # print(e) - # return Response( - # {"error": "Something went wrong please try again later"}, - # status=status.HTTP_400_BAD_REQUEST, - # ) + + except Exception as e: + capture_exception(e) + return Response( + {"error": "Something went wrong please try again later"}, + status=status.HTTP_400_BAD_REQUEST, + ) def create(self, request, slug, project_id): try: @@ -365,6 +358,7 @@ class CycleViewSet(BaseViewSet): try: queryset = self.get_queryset().get(pk=pk) + # Assignee Distribution assignee_distribution = ( Issue.objects.filter( issue_cycle__cycle_id=pk, @@ -374,7 +368,8 @@ class CycleViewSet(BaseViewSet): .annotate(first_name=F("assignees__first_name")) .annotate(last_name=F("assignees__last_name")) .annotate(assignee_id=F("assignees__id")) - .values("first_name", "last_name", "assignee_id") + .annotate(avatar=F("assignees__avatar")) + .values("first_name", "last_name", "assignee_id", "avatar") .annotate(total_issues=Count("assignee_id")) .annotate( completed_issues=Count( @@ -391,6 +386,7 @@ class CycleViewSet(BaseViewSet): .order_by("first_name", "last_name") ) + # Label Distribution label_distribution = ( Issue.objects.filter( issue_cycle__cycle_id=pk, @@ -433,7 +429,10 @@ class CycleViewSet(BaseViewSet): data, status=status.HTTP_200_OK, ) - + except Cycle.DoesNotExist: + return Response( + {"error": "Cycle Does not exists"}, status=status.HTTP_400_BAD_REQUEST + ) except Exception as e: capture_exception(e) return Response(