From 8ee1135ee75becff545f8b0fb779a0eefecb77cd Mon Sep 17 00:00:00 2001 From: aswanthabam Date: Sat, 4 Jan 2025 14:16:35 +0530 Subject: [PATCH] fix(leaderboard): fix leaderboard apis --- api/leaderboard/leaderboard_view.py | 17 +++++++++++------ api/leaderboard/serializers.py | 5 ++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/leaderboard/leaderboard_view.py b/api/leaderboard/leaderboard_view.py index 234672f9..2210043f 100644 --- a/api/leaderboard/leaderboard_view.py +++ b/api/leaderboard/leaderboard_view.py @@ -26,7 +26,7 @@ def get(self, request): queryset=UserOrganizationLink.objects.filter( org__org_type=OrganizationType.COLLEGE.value ).select_related("org"), - to_attr="colleges" + to_attr="colleges", ) ) .order_by("-wallet_user__karma")[:20] @@ -50,7 +50,6 @@ def get(self, request): exist_in_guild=True, ) .annotate( - full_name=F("full_name"), institution=F("user_organization_link_user__org__title"), total_karma=Coalesce( Sum( @@ -70,12 +69,18 @@ def get(self, request): "total_karma", "institution", ) - .order_by("-total_karma") + .order_by("-total_karma")[:20] ) + data = [ + { + "full_name": student.full_name, + "total_karma": student.total_karma, + "institution": student.institution, + } + for student in student_monthly_leaderboard + ] - return CustomResponse( - response=student_monthly_leaderboard - ).get_success_response() + return CustomResponse(response=data).get_success_response() class CollegeLeaderboard(APIView): diff --git a/api/leaderboard/serializers.py b/api/leaderboard/serializers.py index 1edc862d..454b2370 100644 --- a/api/leaderboard/serializers.py +++ b/api/leaderboard/serializers.py @@ -78,9 +78,8 @@ def get_rank(self, obj): class StudentLeaderboardSerializer(serializers.ModelSerializer): institution = serializers.SerializerMethodField() - total_karma = serializers.IntegerField( - source="wallet_user.karma", default=0) - full_name = serializers.CharField(source="full_name") + total_karma = serializers.IntegerField(source="wallet_user.karma", default=0) + full_name = serializers.CharField() def get_institution(self, user): return user.colleges[0].org.title if user.colleges else None