chore: add assignee avatar and minor refactor on cycles list and retrieve endpoint (#1320)

This commit is contained in:
pablohashescobar 2023-06-20 10:25:47 +05:30 committed by GitHub
parent c9ebc20a8e
commit 464c0f2308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(