Refactor client can complete learning contents
This commit is contained in:
parent
c334c25f1c
commit
736ecb2449
|
|
@ -31,7 +31,11 @@ export default {
|
||||||
log.debug('CircleView mounted', this.circleSlug);
|
log.debug('CircleView mounted', this.circleSlug);
|
||||||
itGet(`/learnpath/api/circle/${this.circleSlug}/`).then((data) => {
|
itGet(`/learnpath/api/circle/${this.circleSlug}/`).then((data) => {
|
||||||
this.circleData = data;
|
this.circleData = data;
|
||||||
itGet(`/api/completion/user_circle_completion/${this.circleData.translation_key}/`).then((completionData) => {
|
itGet(`/api/completion/circle/${this.circleData.translation_key}/`).then((completionData) => {
|
||||||
|
let completedLearningContents = {};
|
||||||
|
if (completionData?.json_data?.completed_learning_contents) {
|
||||||
|
completedLearningContents = completionData.json_data.completed_learning_contents;
|
||||||
|
}
|
||||||
|
|
||||||
// aggregate wagtail data into LearningSequence > LearningUnit > LearningPackage hierarchy
|
// aggregate wagtail data into LearningSequence > LearningUnit > LearningPackage hierarchy
|
||||||
let learningSequence = null;
|
let learningSequence = null;
|
||||||
|
|
@ -54,7 +58,7 @@ export default {
|
||||||
learningUnit = Object.assign(child, { learningContents: [] });
|
learningUnit = Object.assign(child, { learningContents: [] });
|
||||||
} else {
|
} else {
|
||||||
// must be a LearningContent
|
// must be a LearningContent
|
||||||
if (child.translation_key in completionData.json_data.completed_learning_contents) {
|
if (child.translation_key in completedLearningContents) {
|
||||||
child.completed = true;
|
child.completed = true;
|
||||||
}
|
}
|
||||||
learningUnit.learningContents.push(child);
|
learningUnit.learningContents.push(child);
|
||||||
|
|
@ -80,7 +84,6 @@ export default {
|
||||||
|
|
||||||
log.debug(this.learningSequences);
|
log.debug(this.learningSequences);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,26 @@ class CompletionApiTestCase(APITestCase):
|
||||||
'learning_content_key': learning_content_key
|
'learning_content_key': learning_content_key
|
||||||
})
|
})
|
||||||
response_json = response.json()
|
response_json = response.json()
|
||||||
print(json.dumps(response.json()))
|
print(json.dumps(response.json(), indent=2))
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 201)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response_json['circle_key'], circle_key)
|
self.assertEqual(response_json['circle_key'], circle_key)
|
||||||
self.assertEqual(response_json['json_data']['completed_learning_contents'][learning_content_key]['learning_content_key'], learning_content_key)
|
self.assertEqual(
|
||||||
|
response_json['json_data']['completed_learning_contents'][learning_content_key]['learning_content_key'],
|
||||||
|
learning_content_key
|
||||||
|
)
|
||||||
|
|
||||||
|
# test getting the circle data
|
||||||
|
response = self.client.get(f'/api/completion/user_circle_completion/{circle_key}/')
|
||||||
|
response_json = response.json()
|
||||||
|
print(json.dumps(response.json(), indent=2))
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response_json['circle_key'], circle_key)
|
||||||
|
self.assertEqual(
|
||||||
|
response_json['json_data']['completed_learning_contents'][learning_content_key]['learning_content_key'],
|
||||||
|
learning_content_key
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@ from django.urls import path
|
||||||
from vbv_lernwelt.completion.views import complete_learning_content, request_user_circle_completion
|
from vbv_lernwelt.completion.views import complete_learning_content, request_user_circle_completion
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(r"user_circle_completion/<uuid:circle_key>/", request_user_circle_completion, name="request_user_circle_completion"),
|
path(r"circle/<uuid:circle_key>/", request_user_circle_completion, name="request_user_circle_completion"),
|
||||||
path(r"complete_learning_content/", complete_learning_content, name="complete_learning_content"),
|
path(r"complete_learning_content/", complete_learning_content, name="complete_learning_content"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,15 @@ logger = structlog.get_logger(__name__)
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
def request_user_circle_completion(request, circle_key):
|
def request_user_circle_completion(request, circle_key):
|
||||||
ucc = UserCircleCompletion.objects.get(
|
ucc = UserCircleCompletion.objects.filter(
|
||||||
user=request.user,
|
user=request.user,
|
||||||
circle_key=circle_key,
|
circle_key=circle_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(status=200, data=UserCircleCompletionSerializer(ucc).data)
|
if ucc.count() > 0:
|
||||||
|
return Response(status=200, data=UserCircleCompletionSerializer(ucc.first()).data)
|
||||||
|
else:
|
||||||
|
return Response(status=200, data={})
|
||||||
|
|
||||||
|
|
||||||
@api_view(['POST'])
|
@api_view(['POST'])
|
||||||
|
|
@ -55,4 +58,4 @@ def complete_learning_content(request):
|
||||||
user_id=request.user.id,
|
user_id=request.user.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(status=201, data=UserCircleCompletionSerializer(ucc).data)
|
return Response(status=200, data=UserCircleCompletionSerializer(ucc).data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue