jira-34 referral code validation API

This commit is contained in:
jain
2023-07-19 17:45:20 +05:30
parent 2e3870dc53
commit 9f9926da14
11 changed files with 106 additions and 16 deletions

View File

@ -37,6 +37,8 @@ from guardian.utils import upload_image_to_alibaba
# search junior API
# remove junior API,
# approve junior API
# create referral code
# validation API
# Create your views here.
class UpdateJuniorProfile(viewsets.ViewSet):
@ -272,3 +274,28 @@ class JuniorPointsListAPIView(viewsets.ModelViewSet):
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)
class ValidateReferralCode(viewsets.ViewSet):
"""Check guardian code exist or not"""
permission_classes = [IsAuthenticated]
def get_queryset(self):
"""Get queryset based on referral_code."""
referral_code = self.request.GET.get('referral_code')
if referral_code:
# search referral code in guardian model
guardian_queryset = Guardian.objects.filter(referral_code=referral_code).last()
if guardian_queryset:
return guardian_queryset
else:
# search referral code in junior model
junior_queryset = Junior.objects.filter(referral_code=referral_code).last()
if junior_queryset:
return junior_queryset
return None
def list(self, request, *args, **kwargs):
"""check guardian code"""
if self.get_queryset():
return custom_response(SUCCESS_CODE['3033'], response_status=status.HTTP_200_OK)
return custom_error_response(ERROR_CODE["2019"], response_status=status.HTTP_400_BAD_REQUEST)