Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add learners enrolment list api #143

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

tehreem-sadat
Copy link
Collaborator

@tehreem-sadat tehreem-sadat commented Nov 15, 2024

Add enrollment api.

Example usage:

To get all enrolments:

/api/fx/learners/v1/enrollments/

[ 
    {
            "user_id": 10,
            "full_name": "user1",
            "alternative_full_name": "عالي",
            "username": "user1",
            "national_id": "",
            "email": "[[email protected]](mailto:[email protected])",
            "mobile_no": null,
            "year_of_birth": null,
            "gender": "",
            "gender_display": null,
            "date_joined": "2024-11-08T12:31:06.322903Z",
            "last_login": "2024-11-15T08:23:03.539659Z",
            "certificate_available": false,
            "course_score": null,
            "active_in_course": false,
            "course_id": "course-v1:bragi_org+111+11"
        },
]
...

To get all enrolments - with complete details

/api/fx/learners/v1/enrollments/?optional_field_tags=__all__

[
    {
            "user_id": 10,
            "full_name": "user1",
            "alternative_full_name": "عالي",
            "username": "user1",
            "national_id": "",
            "email": "[[email protected]](mailto:[email protected])",
            "mobile_no": null,
            "year_of_birth": null,
            "gender": "",
            "gender_display": null,
            "date_joined": "2024-11-08T12:31:06.322903Z",
            "last_login": "2024-11-15T08:23:03.539659Z",
            "certificate_available": false,
            "course_score": null,
            "active_in_course": false,
            "progress": 0.0,
            "certificate_url": null,
            "course_id": "course-v1:bragi_org+111+11",
            "earned - Final Exam: Subsection": "no attempt",
            "possible - Final Exam: Subsection": "no attempt",
            "earned - another: Subsection": "no attempt",
            "possible - another: Subsection": "no attempt"
    }.
...
]

To get all enrolments - for certain courses -> Send ',' separated list of course ids:

/api/fx/learners/v1/enrollments/?course_ids=course_id1, course_id2

To get all enrolments - for certain users -> Send ',' separated list of user ids:

/api/fx/learners/v1/enrollments/?user_ids=1,2

To get all enrolments - for specific user and course -> Send ',' separated list of user ids and course_ids:

/api/fx/learners/v1/enrollments/?user_ids=1,2&course_ids=course_id1

Note:
500 error will be raised for invalid course_ids.

@tehreem-sadat tehreem-sadat force-pushed the tehreem/add_learners_enrollment_api branch 6 times, most recently from 9188f07 to e771ef7 Compare November 19, 2024 10:49
futurex_openedx_extensions/dashboard/serializers.py Outdated Show resolved Hide resolved
futurex_openedx_extensions/dashboard/serializers.py Outdated Show resolved Hide resolved
futurex_openedx_extensions/dashboard/serializers.py Outdated Show resolved Hide resolved
futurex_openedx_extensions/dashboard/serializers.py Outdated Show resolved Hide resolved
@tehreem-sadat tehreem-sadat force-pushed the tehreem/add_learners_enrollment_api branch from e771ef7 to e35c17a Compare November 20, 2024 13:02
@tehreem-sadat tehreem-sadat force-pushed the tehreem/add_learners_enrollment_api branch from e35c17a to ba6f8c8 Compare November 20, 2024 13:07
Copy link
Collaborator

@shadinaif shadinaif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work @tehreem-sadat !

please address my comment about str then it's good to go 👍🏼

Comment on lines 202 to 208
def get_date_joined(self, obj: get_user_model) -> str:
"""Return user ID."""
return str(self._get_user(obj).date_joined) # type: ignore

def get_last_login(self, obj: get_user_model) -> str:
"""Return user ID."""
return str(self._get_user(obj).last_login) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't trust str when converting date and time. At least it is not timezone-aware

Suggested change
def get_date_joined(self, obj: get_user_model) -> str:
"""Return user ID."""
return str(self._get_user(obj).date_joined) # type: ignore
def get_last_login(self, obj: get_user_model) -> str:
"""Return user ID."""
return str(self._get_user(obj).last_login) # type: ignore
def get_date_joined(self, obj: Any) -> str:
date_joined = self._get_user(obj).date_joined
return date_joined.isoformat() if date_joined else None
def get_last_login(self, obj: Any) -> str:
last_login = self._get_user(obj).last_login
return last_login.isoformat() if last_login else None

@@ -340,12 +347,91 @@ def _extract_exam_scores(representation_item: dict[str, Any]) -> None:
representation_item[possible_key] = score[1] if score else 'no attempt'

representation = super().to_representation(instance)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please recover the deleted empty line, here and everywhere unless you intentionally want to delete it

For this one, it is more readable to have the empty lines separating the logic

@tehreem-sadat tehreem-sadat force-pushed the tehreem/add_learners_enrollment_api branch from ba6f8c8 to 8c13c84 Compare November 22, 2024 08:20
@tehreem-sadat tehreem-sadat force-pushed the tehreem/add_learners_enrollment_api branch from 8c13c84 to 7f4ab83 Compare November 22, 2024 08:34
@tehreem-sadat tehreem-sadat merged commit 6ac63f1 into main Nov 22, 2024
3 checks passed
@tehreem-sadat tehreem-sadat deleted the tehreem/add_learners_enrollment_api branch November 22, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants