From 8237529fdddebbd547f3a2e0a1b1fc23841c99b4 Mon Sep 17 00:00:00 2001 From: Adnan Kattekaden Date: Thu, 14 Dec 2023 17:57:43 +0530 Subject: [PATCH] get-logs to public --- api/common/common_views.py | 14 ++++++++++++-- api/common/serializer.py | 29 +++++++++++++++++++++++++++++ api/common/urls.py | 2 ++ api/urls.py | 2 +- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/api/common/common_views.py b/api/common/common_views.py index 7944a5b9..65a9e597 100644 --- a/api/common/common_views.py +++ b/api/common/common_views.py @@ -2,8 +2,8 @@ import requests from django.db import models +from django.db.models import Case, When, Value, CharField, Count, Q, F, Sum from django.db.models import Subquery, OuterRef -from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q from django.db.models.functions import Coalesce from rest_framework.views import APIView @@ -15,7 +15,8 @@ from utils.response import CustomResponse from utils.types import IntegrationType, OrganizationType, RoleType from utils.utils import CommonUtils -from .serializer import StudentInfoSerializer, CollegeInfoSerializer, LearningCircleEnrollmentSerializer +from .serializer import StudentInfoSerializer, CollegeInfoSerializer, LearningCircleEnrollmentSerializer, \ + UserLeaderboardSerializer class LcDashboardAPI(APIView): @@ -578,3 +579,12 @@ def get(self, request): user_karma['igs'] = [] return CustomResponse(response=user_karma_by_ig).get_success_response() + + +class BekenAPI(APIView): + def get(self, request): + user_info = User.objects.exclude( + user_role_link_user__role__title__in=[RoleType.ENABLER.value, RoleType.MENTOR.value]).order_by( + '-wallet_user__karma')[:100] + data = UserLeaderboardSerializer(user_info, many=True) + return CustomResponse(response=data.data).get_success_response() diff --git a/api/common/serializer.py b/api/common/serializer.py index 248516e5..e2e4c97d 100644 --- a/api/common/serializer.py +++ b/api/common/serializer.py @@ -1,5 +1,7 @@ from rest_framework import serializers +from db.user import User + class StudentInfoSerializer(serializers.Serializer): first_name = serializers.CharField() @@ -29,3 +31,30 @@ class LearningCircleEnrollmentSerializer(serializers.Serializer): organisation = serializers.CharField() district = serializers.CharField(allow_null=True) karma_earned = serializers.IntegerField() + + +class UserLeaderboardSerializer(serializers.ModelSerializer): + rank = serializers.SerializerMethodField() + interest_groups = serializers.SerializerMethodField() + organizations = serializers.SerializerMethodField() + karma = serializers.IntegerField(source="wallet_user.karma") + fullname = serializers.SerializerMethodField() + + class Meta: + model = User + fields = ( + 'fullname', + "rank", + "karma", + "interest_groups", + "organizations", + ) + + def get_fullname(self, obj): + return obj.fullname + + def get_organizations(self, obj): + return obj.user_organization_link_user.all().values_list("org__title", flat=True) + + def get_interest_groups(self, obj): + return obj.user_ig_link_user.all().values_list("ig__name", flat=True) diff --git a/api/common/urls.py b/api/common/urls.py index 3d68618b..2b9dd176 100644 --- a/api/common/urls.py +++ b/api/common/urls.py @@ -17,4 +17,6 @@ path('profile-pic//', common_views.UserProfilePicAPI.as_view()), path('list-ig/', common_views.ListIGAPI.as_view()), path('list-ig-top100/', common_views.ListTopIgUsersAPI.as_view()), + + path('leaderboard/top-100/', common_views.BekenAPI.as_view()), ] diff --git a/api/urls.py b/api/urls.py index c8e93777..8aa72d24 100644 --- a/api/urls.py +++ b/api/urls.py @@ -11,7 +11,7 @@ path('protected/', include('api.protected.urls')), path('hackathon/', include('api.hackathon.urls')), path('notification/', include('api.notification.urls')), - path('get-log/', include('api.common.urls')), + path('public/', include('api.common.urls')), path('top100/', include('api.top100_coders.urls')), path("__debug__/", include(debug_toolbar.urls)),