Skip to content

Commit

Permalink
Merge pull request #1885 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
discord moderator api
  • Loading branch information
adnankattekaden authored Dec 30, 2023
2 parents 6f1ca62 + cc151a2 commit ad4767c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
38 changes: 34 additions & 4 deletions api/dashboard/discord_moderator/discord_mod_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,34 @@
from rest_framework.views import APIView

from db.task import KarmaActivityLog
from utils.utils import CommonUtils
from utils.permission import CustomizePermission
from utils.response import CustomResponse
from .serializer import KarmaActivityLogSerializer
from .serializer import KarmaActivityLogSerializer,LeaderboardSerializer


class TaskList(APIView):
authentication_classes = [CustomizePermission]

def get(self, request):
tasks = KarmaActivityLog.objects.all()
serializer = KarmaActivityLogSerializer(tasks, many=True)
return CustomResponse(response=serializer.data).get_success_response()
paginated_queryset = CommonUtils.get_paginated_queryset(
tasks,
request,
['id', 'full_name', 'task_name', 'status', 'discordlink']
)

serializer = KarmaActivityLogSerializer(
paginated_queryset.get("queryset"),
many=True
)

return CustomResponse().paginated_response(
data=serializer.data,
pagination=paginated_queryset.get(
"pagination"
)
)

class PendingTasks(APIView):
authentication_classes = [CustomizePermission]
Expand Down Expand Up @@ -65,4 +80,19 @@ def get(self, request):
for name, info in data.items()
]

return CustomResponse(response=response_data).get_success_response()
paginated_queryset = CommonUtils.get_paginated_queryset(
response_data,
request,
[]
)
serializer = LeaderboardSerializer(
paginated_queryset.get("queryset"),
many=True
)
return CustomResponse().paginated_response(
data=serializer.data,
pagination=paginated_queryset.get(
"pagination"
)
)

10 changes: 10 additions & 0 deletions api/dashboard/discord_moderator/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ def get_status(self, obj):
return "Appraiser Approved"
else:
return "Pending"


class LeaderboardSerializer(serializers.ModelSerializer):
name = serializers.CharField(max_length=100)
count = serializers.IntegerField()
muid = serializers.CharField(max_length=100)

class Meta:
model = KarmaActivityLog
fields = ['name', 'count', 'muid']
1 change: 1 addition & 0 deletions db/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DbConfig(AppConfig):
name = "db"

def ready(self) -> None:
# from db import organization
_ready = super().ready()
self.check_system_user_exists()
return _ready
Expand Down

0 comments on commit ad4767c

Please sign in to comment.