Skip to content

Commit

Permalink
Merge pull request #1947 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Merge dev to dev-server
  • Loading branch information
jelanmathewjames authored May 14, 2024
2 parents da58762 + f24b2c1 commit b7a0e3b
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions api/integrations/wadhwani/wadhwani_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ def post(self, request):
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(url, data=data, headers=headers)

if response.json()["status"] == "ERROR":
return CustomResponse(general_message="Invalid credentials").get_failure_response()
return CustomResponse(response=response.json()).get_success_response()

class WadhwaniUserLogin(APIView):
def post(self, request):
url = settings.WADHWANI_BASE_URL + "/api/v1/iamservice/oauth/login"
token = request.data.get('Client-Auth-Token', None)
course_root_id = request.data.get("course_root_id", None)
user_id = JWTUtils.fetch_user_id(request)
user = User.objects.get(id=user_id)
if not (token := request.data.get('Client-Auth-Token', None)):
return CustomResponse(general_message="Token is required").get_failure_response()

if not (course_root_id := request.data.get("course_root_id", None)):
return CustomResponse(general_message="Course Root ID is required").get_failure_response()

data = {
"name": user.full_name,
"candidateId": user.id,
Expand All @@ -39,35 +46,55 @@ def post(self, request):
"courseRootId": course_root_id
}
response = requests.post(url, data=data)

if response.json()["status"] == "ERROR":
return CustomResponse(general_message="Invalid Input").get_failure_response()
return CustomResponse(response=response.json()).get_success_response()

class WadhwaniCourseDetails(APIView):
def post(self, request):
url = settings.WADHWANI_BASE_URL + "/api/v1/courseservice/oauth/client/courses"
token = request.data.get('Client-Auth-Token', None)

if not (token := request.data.get('Client-Auth-Token', None)):
return CustomResponse(general_message="Token is required").get_failure_response()

headers = {'Authorization': token}
response = requests.get(url, headers=headers)

if response.json()["status"] == "ERROR":
return CustomResponse(general_message="No courses available").get_failure_response()
return CustomResponse(response=response.json()).get_success_response()

class WadhwaniCourseEnrollStatus(APIView):
def post(self, request):
url = settings.WADHWANI_BASE_URL + "/api/v1/courseservice/oauth/client/courses"
token = request.data.get('Client-Auth-Token', None)
headers = {'Authorization': token}
user_id = JWTUtils.fetch_user_id(request)
user = User.objects.get(id=user_id)

if not (token := request.data.get('Client-Auth-Token', None)):
return CustomResponse(general_message="Token is required").get_failure_response()

headers = {'Authorization': token}
response = requests.get(url, params={"username": user.email}, headers=headers)

if response.json()["status"] == "ERROR":
return CustomResponse(general_message="User doesn't have any enrolled courses").get_failure_response()
response = requests.get(url, params={"username": user.email}, headers=headers)
return CustomResponse(response=response.json()).get_success_response()

class WadhwaniCourseQuizData(APIView):
def post(self, request):
token = request.data.get('Client-Auth-Token', None)
course_id = request.data.get('course_id', None)
if not (token := request.data.get('Client-Auth-Token', None)):
return CustomResponse(general_message="Token is required").get_failure_response()

if not (course_id := request.data.get('course_id', None)):
return CustomResponse(general_message="Course ID is required").get_failure_response()

headers = {'Authorization': token}
user_id = JWTUtils.fetch_user_id(request)
user = User.objects.get(id=user_id)
url = settings.WADHWANI_BASE_URL + f"/api/v1/courseservice/oauth/course/{course_id}/reports/quiz/student/{user.email}"
response = requests.get(url, headers=headers)

if response.json()["status"] == "ERROR":
return CustomResponse(general_message="No quiz data available").get_failure_response()
return CustomResponse(response=response.json()).get_success_response()

0 comments on commit b7a0e3b

Please sign in to comment.