mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
Merge branch 'dev' into ZBKADM-73-test-cases
This commit is contained in:
@ -103,9 +103,9 @@ ERROR_CODE = {
|
||||
"2074": "You can not complete this task because you does not exist in the system",
|
||||
# deactivate account
|
||||
"2075": "Your account is deactivated. Please contact with admin",
|
||||
"2076": "This junior already associate with you",
|
||||
"2076": "This junior already associated with you",
|
||||
"2077": "You can not add guardian",
|
||||
"2078": "This junior is not associate with you",
|
||||
"2078": "This junior is not associated with you",
|
||||
# force update
|
||||
"2079": "Please update your app version for enjoying uninterrupted services",
|
||||
"2080": "Can not add App version",
|
||||
|
@ -6,7 +6,7 @@ from .views import (UpdateJuniorProfile, ValidateGuardianCode, JuniorListAPIView
|
||||
CompleteJuniorTaskAPIView, JuniorPointsListAPIView, ValidateReferralCode,
|
||||
InviteGuardianAPIView, StartTaskAPIView, ReAssignJuniorTaskAPIView, StartArticleAPIView,
|
||||
StartAssessmentAPIView, CheckAnswerAPIView, CompleteArticleAPIView, ReadArticleCardAPIView,
|
||||
CreateArticleCardAPIView, RemoveGuardianCodeAPIView, FAQViewSet)
|
||||
CreateArticleCardAPIView, RemoveGuardianCodeAPIView, FAQViewSet, CheckJuniorApiViewSet)
|
||||
"""Third party import"""
|
||||
from rest_framework import routers
|
||||
|
||||
@ -29,6 +29,8 @@ router.register('create-junior-profile', UpdateJuniorProfile, basename='profile-
|
||||
router.register('validate-guardian-code', ValidateGuardianCode, basename='validate-guardian-code')
|
||||
# junior list API"""
|
||||
router.register('junior-list', JuniorListAPIView, basename='junior-list')
|
||||
|
||||
router.register('check-junior', CheckJuniorApiViewSet, basename='check-junior')
|
||||
# Add junior list API"""
|
||||
router.register('add-junior', AddJuniorAPIView, basename='add-junior')
|
||||
# Invited junior list API"""
|
||||
|
@ -164,6 +164,29 @@ class JuniorListAPIView(viewsets.ModelViewSet):
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class CheckJuniorApiViewSet(viewsets.GenericViewSet):
|
||||
"""
|
||||
api to check whether given user exist or not
|
||||
"""
|
||||
serializer_class = None
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
junior = Junior.objects.filter(auth__email=self.request.data.get('email')).first()
|
||||
return junior
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
junior = self.get_queryset()
|
||||
data = {
|
||||
'junior_exist': True if junior else False
|
||||
}
|
||||
return custom_response(None, data)
|
||||
|
||||
|
||||
class AddJuniorAPIView(viewsets.ModelViewSet):
|
||||
"""Add Junior by guardian"""
|
||||
serializer_class = AddJuniorSerializer
|
||||
@ -180,6 +203,16 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
||||
"email":"abc@yopmail.com"
|
||||
}"""
|
||||
try:
|
||||
if user := User.objects.filter(username=request.data['email']).first():
|
||||
data = self.associate_guardian(user)
|
||||
if data == none:
|
||||
return custom_error_response(ERROR_CODE['2077'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
elif not data:
|
||||
return custom_error_response(ERROR_CODE['2076'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
elif data == "Max":
|
||||
return custom_error_response(ERROR_CODE['2081'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
return custom_response(SUCCESS_CODE['3021'], response_status=status.HTTP_200_OK)
|
||||
|
||||
info_data = {'user': request.user, 'relationship': str(request.data['relationship']),
|
||||
'email': request.data['email'], 'first_name': request.data['first_name'],
|
||||
'last_name': request.data['last_name'], 'image':None}
|
||||
@ -193,15 +226,7 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
||||
# upload image on ali baba
|
||||
image_url = upload_image_to_alibaba(profile_image, filename)
|
||||
info_data.update({"image": image_url})
|
||||
if user := User.objects.filter(username=request.data['email']).first():
|
||||
data = self.associate_guardian(user)
|
||||
if data == none:
|
||||
return custom_error_response(ERROR_CODE['2077'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
elif not data:
|
||||
return custom_error_response(ERROR_CODE['2076'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
elif data == "Max":
|
||||
return custom_error_response(ERROR_CODE['2081'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
return custom_response(SUCCESS_CODE['3021'], response_status=status.HTTP_200_OK)
|
||||
|
||||
# use AddJuniorSerializer serializer
|
||||
serializer = AddJuniorSerializer(data=request.data, context=info_data)
|
||||
if serializer.is_valid():
|
||||
|
Reference in New Issue
Block a user