jira-15 leader board API and profile API

This commit is contained in:
jain
2023-07-10 14:53:43 +05:30
parent 026bfb6da7
commit c8925aad8e
6 changed files with 45 additions and 13 deletions

View File

@ -143,7 +143,7 @@ class SearchTaskListAPIView(viewsets.ModelViewSet):
class TopJuniorListAPIView(viewsets.ModelViewSet):
"""Top juniors list"""
serializer_class = TopJuniorSerializer
permission_classes = [IsAuthenticated]
# permission_classes = [IsAuthenticated]
queryset = JuniorPoints.objects.all()
def get_serializer_context(self):
@ -152,8 +152,14 @@ class TopJuniorListAPIView(viewsets.ModelViewSet):
return context
def list(self, request, *args, **kwargs):
"""fetch junior list those complete their task"""
"""Fetch junior list of those who complete their tasks"""
junior_total_points = self.get_queryset().order_by('-total_task_points')
# Update the position field for each JuniorPoints object
for index, junior in enumerate(junior_total_points):
junior.position = index + 1
junior.save()
serializer = self.get_serializer(junior_total_points, many=True)
return custom_response(serializer.data, response_status=status.HTTP_200_OK)