[FC-0031] Mobile API Migration Solution Notes
High-level notes about changes RG introduced in the edx-plugin to correct behavior for mobile apps.
DeactivateLogoutView
As mobile apps are using bearer token auth, the BearerAuthentication
class authentication_classes
for this API View should be added. This view is used in the mobile account settings, to allow user deactivate (delete) their account from the system.
UserCourseEnrollmentsList
https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mobile_api/users/views.py#L253
The pagination is necessary to optimize course loading in the mobile app.
Solution:
Increment API version to version 3
Introduce
DefaultPagination
class to the API’s, paginator property
urlpatterns += [
re_path(r'^api/mobile/(?P<api_version>v(3|2|1|0.5))/', include('lms.djangoapps.mobile_api.urls')),
]
@property
def paginator(self):
super().paginator
api_version = self.kwargs.get('api_version')
if self._paginator is None and api_version == API_V3:
self._paginator = DefaultPagination
return self._paginator
CommentViewSet
https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/discussion/rest_api/views.py#L746
It is required to extend POST response with the data about profile image. This way it’s possible to load avatar image for a post or response without an additional request to a separate account settings endpoint.
"profile_image": {
"has_image": true,
"image_url_full": "http://localhost:18000/media/profile-images/765490233e5640ad12a58d58370a3512_500.jpg?v=1677749000",
"image_url_large": "http://localhost:18000/media/profile-images/765490233e5640ad12a58d58370a3512_120.jpg?v=1677749000",
"image_url_medium": "http://localhost:18000/media/profile-images/765490233e5640ad12a58d58370a3512_50.jpg?v=1677749000",
"image_url_small": "http://localhost:18000/media/profile-images/765490233e5640ad12a58d58370a3512_30.jpg?v=1677749000"
}
Solution:
Add field profile_image
to CommentSerializer
_filter_by_search
Bug
While searching for courses using API api/courses/v1/courses/
and providing search_term
query parameter, pagination
object returns an incorrect count for all pages except for the last page.
Solution:
A new endpoint to get the course home data
The endpoint should extend BlocksInCourseView, and add more data about a course as media
, course dates
, certificate
etc.
Solution:
This endpoint can be added into mobile_api LMS application. In the future, this endpoint can be extended to be a course home endpoint for a mobile.
Example response:
BlocksInCourseView response +
A new endpoint to return about course information
This view can be based on the CourseDetailView and CourseHomeMetadataView, but additionally should provide if user is enrolled to the course or not (maybe if user has some specific visibility conditions.
Solution:
Add a new endpoint into mobile_api LMS application. URL for the new endpoint /mobile/{api_version}/course_info/{course_id}