mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
jira-34 points earned
This commit is contained in:
@ -73,7 +73,8 @@ ERROR_CODE = {
|
|||||||
# add article msg
|
# add article msg
|
||||||
"2041": "Article with given id doesn't exist.",
|
"2041": "Article with given id doesn't exist.",
|
||||||
"2042": "Article Card with given id doesn't exist.",
|
"2042": "Article Card with given id doesn't exist.",
|
||||||
"2043": "Article Survey with given id doesn't exist."
|
"2043": "Article Survey with given id doesn't exist.",
|
||||||
|
"2044": "Task does not exist"
|
||||||
}
|
}
|
||||||
"""Success message code"""
|
"""Success message code"""
|
||||||
SUCCESS_CODE = {
|
SUCCESS_CODE = {
|
||||||
@ -119,6 +120,7 @@ SUCCESS_CODE = {
|
|||||||
"3029": "Article has been deleted successfully.",
|
"3029": "Article has been deleted successfully.",
|
||||||
"3030": "Article Card has been removed successfully.",
|
"3030": "Article Card has been removed successfully.",
|
||||||
"3031": "Article Survey has been removed successfully.",
|
"3031": "Article Survey has been removed successfully.",
|
||||||
|
"3032": "Task request sent successfully"
|
||||||
}
|
}
|
||||||
"""status code error"""
|
"""status code error"""
|
||||||
STATUS_CODE_ERROR = {
|
STATUS_CODE_ERROR = {
|
||||||
|
@ -62,7 +62,7 @@ class SignupViewset(viewsets.ModelViewSet):
|
|||||||
user_type=str(request.data['user_type']), expired_at=expiry)
|
user_type=str(request.data['user_type']), expired_at=expiry)
|
||||||
"""Send email to the register user"""
|
"""Send email to the register user"""
|
||||||
send_otp_email(request.data['email'], otp)
|
send_otp_email(request.data['email'], otp)
|
||||||
return custom_response(SUCCESS_CODE['3001'], {"email_otp": otp},
|
return custom_response(SUCCESS_CODE['3001'],
|
||||||
response_status=status.HTTP_200_OK)
|
response_status=status.HTTP_200_OK)
|
||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
else:
|
else:
|
||||||
|
@ -320,3 +320,49 @@ class CompleteTaskSerializer(serializers.ModelSerializer):
|
|||||||
instance.is_approved = False
|
instance.is_approved = False
|
||||||
instance.save()
|
instance.save()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
class JuniorPointsSerializer(serializers.ModelSerializer):
|
||||||
|
"""Junior points serializer"""
|
||||||
|
|
||||||
|
total_points = serializers.SerializerMethodField('get_points')
|
||||||
|
in_progress_task = serializers.SerializerMethodField('get_in_progress_task')
|
||||||
|
completed_task = serializers.SerializerMethodField('get_completed_task')
|
||||||
|
requested_task = serializers.SerializerMethodField('get_requested_task')
|
||||||
|
rejected_task = serializers.SerializerMethodField('get_rejected_task')
|
||||||
|
pending_task = serializers.SerializerMethodField('get_pending_task')
|
||||||
|
position = serializers.SerializerMethodField('get_position')
|
||||||
|
|
||||||
|
def get_position(self, obj):
|
||||||
|
data = JuniorPoints.objects.filter(junior=obj.junior).last()
|
||||||
|
if data:
|
||||||
|
return data.position
|
||||||
|
return 99999
|
||||||
|
def get_points(self, obj):
|
||||||
|
"""total points"""
|
||||||
|
points = JuniorPoints.objects.filter(junior=obj.junior).last()
|
||||||
|
if points:
|
||||||
|
return points.total_task_points
|
||||||
|
|
||||||
|
def get_in_progress_task(self, obj):
|
||||||
|
return JuniorTask.objects.filter(junior=obj.junior, task_status=IN_PROGRESS).count()
|
||||||
|
|
||||||
|
def get_completed_task(self, obj):
|
||||||
|
return JuniorTask.objects.filter(junior=obj.junior, task_status=COMPLETED).count()
|
||||||
|
|
||||||
|
|
||||||
|
def get_requested_task(self, obj):
|
||||||
|
return JuniorTask.objects.filter(junior=obj.junior, task_status=REQUESTED).count()
|
||||||
|
|
||||||
|
|
||||||
|
def get_rejected_task(self, obj):
|
||||||
|
return JuniorTask.objects.filter(junior=obj.junior, task_status=REJECTED).count()
|
||||||
|
|
||||||
|
|
||||||
|
def get_pending_task(self, obj):
|
||||||
|
return JuniorTask.objects.filter(junior=obj.junior, task_status=PENDING).count()
|
||||||
|
|
||||||
|
class Meta(object):
|
||||||
|
"""Meta info"""
|
||||||
|
model = Junior
|
||||||
|
fields = ['id', 'total_points', 'position', 'pending_task', 'in_progress_task', 'completed_task',
|
||||||
|
'requested_task', 'rejected_task']
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from .views import (UpdateJuniorProfile, ValidateGuardianCode, JuniorListAPIView, AddJuniorAPIView,
|
from .views import (UpdateJuniorProfile, ValidateGuardianCode, JuniorListAPIView, AddJuniorAPIView,
|
||||||
InvitedJuniorAPIView, FilterJuniorAPIView, RemoveJuniorAPIView, JuniorTaskListAPIView,
|
InvitedJuniorAPIView, FilterJuniorAPIView, RemoveJuniorAPIView, JuniorTaskListAPIView,
|
||||||
CompleteJuniorTaskAPIView)
|
CompleteJuniorTaskAPIView, JuniorPointsListAPIView)
|
||||||
"""Third party import"""
|
"""Third party import"""
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
@ -34,6 +34,8 @@ router.register('invited-junior', InvitedJuniorAPIView, basename='invited-junior
|
|||||||
router.register('filter-junior', FilterJuniorAPIView, basename='filter-junior')
|
router.register('filter-junior', FilterJuniorAPIView, basename='filter-junior')
|
||||||
# junior's task list API"""
|
# junior's task list API"""
|
||||||
router.register('junior-task-list', JuniorTaskListAPIView, basename='junior-task-list')
|
router.register('junior-task-list', JuniorTaskListAPIView, basename='junior-task-list')
|
||||||
|
# junior's task list API"""
|
||||||
|
router.register('junior-points', JuniorPointsListAPIView, basename='junior-points')
|
||||||
# Define url pattern"""
|
# Define url pattern"""
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/v1/', include(router.urls)),
|
path('api/v1/', include(router.urls)),
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
"""Junior view file"""
|
"""Junior view file"""
|
||||||
|
import os
|
||||||
|
|
||||||
from rest_framework import viewsets, status, generics,views
|
from rest_framework import viewsets, status, generics,views
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.pagination import PageNumberPagination
|
from rest_framework.pagination import PageNumberPagination
|
||||||
|
import requests
|
||||||
"""Django app import"""
|
"""Django app import"""
|
||||||
|
|
||||||
# Import guardian's model,
|
# Import guardian's model,
|
||||||
@ -17,7 +20,7 @@ from rest_framework.pagination import PageNumberPagination
|
|||||||
# Import account's task
|
# Import account's task
|
||||||
from junior.models import Junior
|
from junior.models import Junior
|
||||||
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,\
|
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,\
|
||||||
RemoveJuniorSerializer, CompleteTaskSerializer)
|
RemoveJuniorSerializer, CompleteTaskSerializer, JuniorPointsSerializer)
|
||||||
from guardian.models import Guardian, JuniorTask
|
from guardian.models import Guardian, JuniorTask
|
||||||
from guardian.serializers import TaskDetailsSerializer
|
from guardian.serializers import TaskDetailsSerializer
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
@ -90,6 +93,11 @@ class JuniorListAPIView(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
""" junior list"""
|
""" junior list"""
|
||||||
|
auth_token = self.request.META['HTTP_AUTHORIZATION']
|
||||||
|
headers_token = {
|
||||||
|
'Authorization': auth_token
|
||||||
|
}
|
||||||
|
requests.get(os.getenv('BASE_URL') + '/api/v1/top-junior/', headers=headers_token)
|
||||||
guardian_data = Guardian.objects.filter(user__email=request.user).last()
|
guardian_data = Guardian.objects.filter(user__email=request.user).last()
|
||||||
queryset = Junior.objects.filter(guardian_code__icontains=str(guardian_data.guardian_code))
|
queryset = Junior.objects.filter(guardian_code__icontains=str(guardian_data.guardian_code))
|
||||||
# use JuniorDetailListSerializer serializer
|
# use JuniorDetailListSerializer serializer
|
||||||
@ -238,7 +246,27 @@ class CompleteJuniorTaskAPIView(views.APIView):
|
|||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
# save serializer
|
# save serializer
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return custom_response(SUCCESS_CODE['3022'], serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3032'], serializer.data, response_status=status.HTTP_200_OK)
|
||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE['2034'], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE['2044'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
|
class JuniorPointsListAPIView(viewsets.ModelViewSet):
|
||||||
|
"""Junior Points viewset"""
|
||||||
|
serializer_class = JuniorPointsSerializer
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
"""get queryset"""
|
||||||
|
return JuniorTask.objects.filter(junior__auth__email=self.request.user).last()
|
||||||
|
def list(self, request, *args, **kwargs):
|
||||||
|
"""profile view"""
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
token = self.request.META['HTTP_AUTHORIZATION']
|
||||||
|
headers = {
|
||||||
|
'Authorization': token
|
||||||
|
}
|
||||||
|
requests.get(os.getenv('BASE_URL') + '/api/v1/top-junior/', headers=headers)
|
||||||
|
serializer = JuniorPointsSerializer(queryset)
|
||||||
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
Reference in New Issue
Block a user