Skip to content

Commit

Permalink
fix(leaderboard): fix leaderboard apis
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanthabam committed Jan 4, 2025
1 parent efbcd01 commit 8ee1135
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 11 additions & 6 deletions api/leaderboard/leaderboard_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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(
Expand All @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions api/leaderboard/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ee1135

Please sign in to comment.