From 30d233fe4b505f7b143edd6a0d8b3b0670bbe351 Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Thu, 18 Jul 2024 12:18:55 +0500 Subject: [PATCH] feat: update stats API --- .../course_progress/api/v1/views.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/openedx/features/sdaia_features/course_progress/api/v1/views.py b/openedx/features/sdaia_features/course_progress/api/v1/views.py index 8f0fea80223..10c5a26d9a7 100644 --- a/openedx/features/sdaia_features/course_progress/api/v1/views.py +++ b/openedx/features/sdaia_features/course_progress/api/v1/views.py @@ -122,8 +122,25 @@ def get(self, request): criteria=F("badge_class__criteria"), image=F("badge_class__image"), ) + transformed_user_badges = [] for badge in user_badges: - badge["course_id"] = str(badge["course_id"]) + badge_image = badge["image"] + transformed_user_badges.append( + { + "image_url": badge["image_url"], + "assertion_url": badge["assertion_url"], + "created": badge["created"], + "badge_class": { + "slug": badge["slug"], + "issuing_component": badge["issuing_component"], + "display_name": badge["display_name"], + "course_id": str(badge["course_id"]), + "description": badge["description"], + "criteria": badge["criteria"], + "image_url": f"{settings.LMS_ROOT_URL}{settings.MEDIA_URL}{badge_image}", + }, + } + ) ############ USER SCORE ############ leaderboard = LeaderboardEntry.objects.filter(user=user) @@ -138,7 +155,7 @@ def get(self, request): "enrolled_programs": no_of_programs, "score": score, "user_certificates": user_certificates, - "user_badges": user_badges, + "user_badges": transformed_user_badges, }, )