diff --git a/kolibri/plugins/learn/frontend/__mocks__/apiResources.js b/kolibri/plugins/learn/frontend/__mocks__/apiResources.js index 69316edba42..54fccf700e5 100644 --- a/kolibri/plugins/learn/frontend/__mocks__/apiResources.js +++ b/kolibri/plugins/learn/frontend/__mocks__/apiResources.js @@ -1,3 +1,3 @@ export const LearnerClassroomResource = { - fetchCollection: jest.fn(), + list: jest.fn(), }; diff --git a/kolibri/plugins/learn/frontend/apiResources.js b/kolibri/plugins/learn/frontend/apiResources.js index 784d68e6fa8..487deff343b 100644 --- a/kolibri/plugins/learn/frontend/apiResources.js +++ b/kolibri/plugins/learn/frontend/apiResources.js @@ -3,9 +3,7 @@ import { Resource } from 'kolibri/apiResource'; /** * Gets all of the Classrooms in which a Learner is enrolled. * @example To get Classrooms without assignments and progress: - * LearnerClassroomResource.fetchCollection({ - * getParams: { no_assignments: true }, - * }) + * LearnerClassroomResource.list({ no_assignments: true }) */ export const LearnerClassroomResource = new Resource({ name: 'learnerclassroom', @@ -24,7 +22,7 @@ export const LearnerCourseResource = new Resource({ name: 'learnercourse', namespace: 'kolibri.plugins.learn', async getResumeData(id) { - const response = await this.accessDetailEndpoint('get', 'resume', id); + const response = await this.request({ action: 'resume', routeParams: id }); return response.data; }, }); diff --git a/kolibri/plugins/learn/frontend/composables/__tests__/useLearnerResources.spec.js b/kolibri/plugins/learn/frontend/composables/__tests__/useLearnerResources.spec.js index 02b5686e013..65d90a7713c 100644 --- a/kolibri/plugins/learn/frontend/composables/__tests__/useLearnerResources.spec.js +++ b/kolibri/plugins/learn/frontend/composables/__tests__/useLearnerResources.spec.js @@ -224,7 +224,7 @@ function finishClasses(classes) { describe(`useLearnerResources`, () => { beforeEach(() => { - LearnerClassroomResource.fetchCollection.mockResolvedValue(TEST_CLASSES); + LearnerClassroomResource.list.mockResolvedValue(TEST_CLASSES); return fetchClasses(); }); @@ -448,21 +448,21 @@ describe(`useLearnerResources`, () => { describe(`learnerFinishedAllClasses`, () => { it(`returns 'true' if a learner has no classes`, () => { - LearnerClassroomResource.fetchCollection.mockResolvedValue([]); + LearnerClassroomResource.list.mockResolvedValue([]); return fetchClasses().then(() => { expect(learnerFinishedAllClasses.value).toBe(true); }); }); it(`returns 'false' if a learner hasn't finished all lessons and quizzes yet`, () => { - LearnerClassroomResource.fetchCollection.mockResolvedValue(TEST_CLASSES); + LearnerClassroomResource.list.mockResolvedValue(TEST_CLASSES); return fetchClasses().then(() => { expect(learnerFinishedAllClasses.value).toBe(false); }); }); it(`returns 'true' if a learner finished all lessons and quizzes`, () => { - LearnerClassroomResource.fetchCollection.mockResolvedValue(finishClasses(TEST_CLASSES)); + LearnerClassroomResource.list.mockResolvedValue(finishClasses(TEST_CLASSES)); return fetchClasses().then(() => { expect(learnerFinishedAllClasses.value).toBe(true); }); diff --git a/kolibri/plugins/learn/frontend/composables/useBookmarks.js b/kolibri/plugins/learn/frontend/composables/useBookmarks.js index 639020b7b3a..2a8868610b4 100644 --- a/kolibri/plugins/learn/frontend/composables/useBookmarks.js +++ b/kolibri/plugins/learn/frontend/composables/useBookmarks.js @@ -100,10 +100,7 @@ export default function useBookmarks() { * @public */ async function fetchBookmarks(getParams) { - const bookmarksData = await BookmarksResource.fetchCollection({ - getParams, - force: true, - }); + const bookmarksData = await BookmarksResource.list(getParams); const bookmarks = bookmarksData ? bookmarksData : []; for (const bookmark of bookmarks) { setBookmark(bookmark); diff --git a/kolibri/plugins/learn/frontend/composables/useContentNodeProgress.js b/kolibri/plugins/learn/frontend/composables/useContentNodeProgress.js index 614aaad55eb..2ea057647fc 100644 --- a/kolibri/plugins/learn/frontend/composables/useContentNodeProgress.js +++ b/kolibri/plugins/learn/frontend/composables/useContentNodeProgress.js @@ -40,10 +40,7 @@ export default function useContentNodeProgress() { * @public */ function fetchContentNodeProgress(getParams) { - return ContentNodeProgressResource.fetchCollection({ - getParams, - force: true, - }).then(progressData => { + return ContentNodeProgressResource.list(getParams).then(progressData => { const progresses = progressData ? progressData : []; for (const progress of progresses) { setContentNodeProgress(progress); @@ -64,7 +61,7 @@ export default function useContentNodeProgress() { * @public */ function fetchContentNodeTreeProgress({ id, params }) { - return ContentNodeProgressResource.fetchTree({ + return ContentNodeProgressResource.fetchTree_v2({ params, id, }).then(progressData => { diff --git a/kolibri/plugins/learn/frontend/composables/useDevices.js b/kolibri/plugins/learn/frontend/composables/useDevices.js index 56ac3c61b38..be1d4f2cb55 100644 --- a/kolibri/plugins/learn/frontend/composables/useDevices.js +++ b/kolibri/plugins/learn/frontend/composables/useDevices.js @@ -41,11 +41,10 @@ function canAccessStudio() { function fetchDevices() { return Promise.all([ - canAccessStudio() ? RemoteChannelResource.getKolibriStudioStatus() : Promise.resolve(null), + canAccessStudio() ? RemoteChannelResource.getKolibriStudioStatus_v2() : Promise.resolve(null), NetworkLocationResource.list(), - ]).then(([studioResponse, devices]) => { + ]).then(([studio, devices]) => { if (canAccessStudio()) { - const studio = studioResponse.data; devices = devices.filter(device => isMinimumKolibriVersion(device.kolibri_version)); if (studio.available && isMinimumKolibriVersion(studio.kolibri_version || '0.15.0')) { return [ @@ -71,7 +70,7 @@ export function setCurrentDevice(id) { set(currentDevice, KolibriStudioDeviceData); return Promise.resolve(KolibriStudioDeviceData); } - return NetworkLocationResource.fetchModel({ id }).then(device => { + return NetworkLocationResource.retrieve(id).then(device => { set(currentDevice, device); return device; }); diff --git a/kolibri/plugins/learn/frontend/composables/useDownloadRequests.js b/kolibri/plugins/learn/frontend/composables/useDownloadRequests.js index d1c0f9e3bd7..976b6960499 100644 --- a/kolibri/plugins/learn/frontend/composables/useDownloadRequests.js +++ b/kolibri/plugins/learn/frontend/composables/useDownloadRequests.js @@ -171,9 +171,7 @@ export default function useDownloadRequests(store) { if (!contentRequest) { return Promise.resolve(); } - ContentRequestResource.deleteModel({ - id: contentRequest.id, - }); + ContentRequestResource.delete(contentRequest.id); Vue.delete(downloadRequestMap, contentRequest.contentnode_id); createSnackbar({ text: downloadRequestsTranslator.$tr('resourceRemoved'), diff --git a/kolibri/plugins/learn/frontend/composables/useLearnerResources.js b/kolibri/plugins/learn/frontend/composables/useLearnerResources.js index 5d77503ac03..42c1b49e647 100644 --- a/kolibri/plugins/learn/frontend/composables/useLearnerResources.js +++ b/kolibri/plugins/learn/frontend/composables/useLearnerResources.js @@ -294,12 +294,11 @@ export default function useLearnerResources() { * to this composable's store * @param {object} params - Request parameters * @param {string} params.classId - Classroom id to load - * @param {boolean} [params.force] - Cache won't be used when `true` * @returns {Promise} - Resolves with the loaded classroom * @public */ - function fetchClass({ classId, force = false }) { - return LearnerClassroomResource.fetchModel({ id: classId, force }).then(classroom => { + function fetchClass({ classId }) { + return LearnerClassroomResource.retrieve(classId).then(classroom => { const updatedClasses = [...get(classes).filter(c => c.id !== classId), classroom]; set(classes, updatedClasses); setClassData(classroom); @@ -310,19 +309,17 @@ export default function useLearnerResources() { /** * Fetches current learner's classes * and saves data to this composable's store - * @param {object} [params] - Request parameters - * @param {boolean} [params.force] - Cache won't be used when `true` * @returns {Promise} - Resolves once the classes store has been populated * @public */ - function fetchClasses({ force = false } = {}) { - return LearnerClassroomResource.fetchCollection({ force }).then(collection => { + function fetchClasses() { + return LearnerClassroomResource.list().then(collection => { set(classes, collection); }); } function fetchLesson({ lessonId } = {}) { - return LearnerLessonResource.fetchModel({ id: lessonId }).then(lesson => { + return LearnerLessonResource.retrieve(lessonId).then(lesson => { _cacheLessonResources(lesson); return lesson; }); @@ -413,12 +410,11 @@ export default function useLearnerResources() { * to this composable's store * @param {object} params - Request parameters * @param {string} params.courseSessionId - Learner course session id - * @param {boolean} [params.force] - Cache won't be used when `true` * @returns {Promise} Course data * @public */ - async function fetchCourse({ courseSessionId, force = false }) { - const course = await LearnerCourseResource.fetchModel({ id: courseSessionId, force }); + async function fetchCourse({ courseSessionId }) { + const course = await LearnerCourseResource.retrieve(courseSessionId); if (!course) { throw new Error('Course not found'); @@ -430,7 +426,7 @@ export default function useLearnerResources() { // Fetch course content tree and learner course progress const [content, progressResponse] = await Promise.all([ - course.course_id ? ContentNodeResource.fetchTree({ id: course.course_id }) : null, + course.course_id ? ContentNodeResource.fetchTree_v2({ id: course.course_id }) : null, LearnerCourseResource.getResumeData(course.id), ]); @@ -445,13 +441,11 @@ export default function useLearnerResources() { /** * Fetches current learner's courses * and saves data to this composable's store - * @param {object} [params] - Request parameters - * @param {boolean} [params.force] - Cache won't be used when `true` * @returns {Promise} - Resolves with the loaded course collection * @public */ - async function fetchCourses({ force = false } = {}) { - const collection = await LearnerCourseResource.fetchCollection({ force }); + async function fetchCourses() { + const collection = await LearnerCourseResource.list(); set(courses, collection); return collection; } diff --git a/kolibri/plugins/learn/frontend/composables/usePinnedDevices.js b/kolibri/plugins/learn/frontend/composables/usePinnedDevices.js index b48f106678d..107679063bd 100644 --- a/kolibri/plugins/learn/frontend/composables/usePinnedDevices.js +++ b/kolibri/plugins/learn/frontend/composables/usePinnedDevices.js @@ -21,7 +21,7 @@ export default function usePinnedDevices(networkDevicesWithChannels) { }); function fetchPinsForUser() { - return PinnedDeviceResource.fetchCollection({ force: true }).then(pins => { + return PinnedDeviceResource.list().then(pins => { const updatedPins = {}; for (const pin of pins) { updatedPins[pin.instance_id] = pin; @@ -51,7 +51,7 @@ export default function usePinnedDevices(networkDevicesWithChannels) { delete newMap[instance_id]; set(userPinsMap, newMap); createSnackbar(PinStrings.$tr('pinRemoved')); - return PinnedDeviceResource.deleteModel({ id }); + return PinnedDeviceResource.delete(id); } function _isPinnedDevice(device) { diff --git a/kolibri/plugins/learn/frontend/modules/classes/handlers.js b/kolibri/plugins/learn/frontend/modules/classes/handlers.js index b95b1745134..2de3e4cfa78 100644 --- a/kolibri/plugins/learn/frontend/modules/classes/handlers.js +++ b/kolibri/plugins/learn/frontend/modules/classes/handlers.js @@ -6,7 +6,7 @@ import { ClassesPageNames } from '../../constants'; // Shows a list of all the Classrooms a Learner is enrolled in export function showAllClassesPage(store) { pageLoading.value = true; - return LearnerClassroomResource.fetchCollection() + return LearnerClassroomResource.list() .then(classrooms => { store.commit('SET_PAGE_NAME', ClassesPageNames.ALL_CLASSES); store.commit('classes/SET_LEARNER_CLASSROOMS', classrooms); diff --git a/kolibri/plugins/learn/frontend/modules/examViewer/handlers.js b/kolibri/plugins/learn/frontend/modules/examViewer/handlers.js index 36d1df4fe59..6be676195ca 100644 --- a/kolibri/plugins/learn/frontend/modules/examViewer/handlers.js +++ b/kolibri/plugins/learn/frontend/modules/examViewer/handlers.js @@ -23,10 +23,7 @@ export function showExam(store, params, alreadyOnQuiz, route) { handleError('You must be logged in as a learner to view this page'); pageLoading.value = false; } else { - const promises = [ - LearnerClassroomResource.fetchModel({ id: classId }), - ExamResource.fetchModel({ id: examId }), - ]; + const promises = [LearnerClassroomResource.retrieve(classId), ExamResource.retrieve(examId)]; const shouldResolve = samePageCheckGenerator(route); Promise.all(promises).then( ([classroom, exam]) => { diff --git a/kolibri/plugins/learn/frontend/modules/lessonPlaylist/handlers.js b/kolibri/plugins/learn/frontend/modules/lessonPlaylist/handlers.js index 5eddf2f1304..4fa5f7fac38 100644 --- a/kolibri/plugins/learn/frontend/modules/lessonPlaylist/handlers.js +++ b/kolibri/plugins/learn/frontend/modules/lessonPlaylist/handlers.js @@ -18,7 +18,7 @@ export function showLessonPlaylist(store, { lessonId }) { fetchContentNodeProgress({ lesson: lessonId }); } const contentNodePromise = ContentNodeResource.fetchLessonResources(lessonId); - return LearnerLessonResource.fetchModel({ id: lessonId }) + return LearnerLessonResource.retrieve(lessonId) .then(lesson => { store.commit('SET_PAGE_NAME', ClassesPageNames.LESSON_PLAYLIST); store.commit('lessonPlaylist/SET_CURRENT_LESSON', lesson); diff --git a/kolibri/plugins/learn/frontend/views/BookmarkPage.vue b/kolibri/plugins/learn/frontend/views/BookmarkPage.vue index f6dfcb1c912..59f354db888 100644 --- a/kolibri/plugins/learn/frontend/views/BookmarkPage.vue +++ b/kolibri/plugins/learn/frontend/views/BookmarkPage.vue @@ -149,18 +149,20 @@ }; }, created() { - ContentNodeResource.fetchBookmarks({ params: { limit: 25, available: true } }).then(data => { - this.more = data.more; - this.bookmarks = data.results ? data.results : []; - this.loading = false; - this.fetchContentNodeProgress({ ids: this.bookmarks.map(b => b.id) }); - }); + ContentNodeResource.fetchBookmarks_v2({ params: { limit: 25, available: true } }).then( + data => { + this.more = data.more; + this.bookmarks = data.results ? data.results : []; + this.loading = false; + this.fetchContentNodeProgress({ ids: this.bookmarks.map(b => b.id) }); + }, + ); }, methods: { loadMore() { if (!this.loading) { this.loading = true; - ContentNodeResource.fetchBookmarks({ params: this.more }).then(data => { + ContentNodeResource.fetchBookmarks_v2({ params: this.more }).then(data => { this.more = data.more; this.bookmarks.push(...data.results); this.loading = false; diff --git a/kolibri/plugins/learn/frontend/views/BrowseResourceMetadata.vue b/kolibri/plugins/learn/frontend/views/BrowseResourceMetadata.vue index 736eae50e3d..bb61b64033c 100644 --- a/kolibri/plugins/learn/frontend/views/BrowseResourceMetadata.vue +++ b/kolibri/plugins/learn/frontend/views/BrowseResourceMetadata.vue @@ -341,15 +341,16 @@ }, }, mounted() { - ContentNodeResource.fetchRecommendationsFor(this.content.id).then(recommendations => { + ContentNodeResource.fetchRecommendationsFor_v2(this.content.id).then(recommendations => { const threeRecs = recommendations.splice(0, 3); this.recommendations = threeRecs.length ? threeRecs : null; }); if (this.showLocationsInChannel) { // Retreives any topics in this same channel - ContentNodeResource.fetchCollection({ - getParams: { content_id: this.content.content_id, channel_id: this.content.channel_id }, + ContentNodeResource.list({ + content_id: this.content.content_id, + channel_id: this.content.channel_id, }).then((locations = []) => { locations = locations.filter(loc => loc.id !== this.content.id); if (locations && locations.length) { diff --git a/kolibri/plugins/learn/frontend/views/ChannelRenderer/CustomContentRenderer.vue b/kolibri/plugins/learn/frontend/views/ChannelRenderer/CustomContentRenderer.vue index aa277ba17db..a754655326c 100644 --- a/kolibri/plugins/learn/frontend/views/ChannelRenderer/CustomContentRenderer.vue +++ b/kolibri/plugins/learn/frontend/views/ChannelRenderer/CustomContentRenderer.vue @@ -144,18 +144,16 @@ // limit to channel, defaults to true const limitToChannel = 'limitToChannel' in options ? options.limitToChannel : true; - return ContentNodeResource.fetchCollection({ - getParams: { - ids: options.ids, - authors: options.authors, - tags: options.tags, - parent: options.parent === 'self' ? this.topic.id : options.parent, - channel_id: limitToChannel ? this.topic.channel_id : undefined, - max_results: options.maxResults ? options.maxResults : 50, - kind: kind, - kind_in: kinds, - descendant_of: options.descendantOf, - }, + return ContentNodeResource.list({ + ids: options.ids, + authors: options.authors, + tags: options.tags, + parent: options.parent === 'self' ? this.topic.id : options.parent, + channel_id: limitToChannel ? this.topic.channel_id : undefined, + max_results: options.maxResults ? options.maxResults : 50, + kind: kind, + kind_in: kinds, + descendant_of: options.descendantOf, }) .then(contentNodes => { const { more, results } = contentNodes; @@ -180,9 +178,7 @@ fetchMore(message) { const { options } = message; - return ContentNodeResource.fetchCollection({ - getParams: options, - }) + return ContentNodeResource.list(options) .then(contentNodes => { const { more, results } = contentNodes; @@ -204,7 +200,7 @@ }, fetchContentModel(message) { - return ContentNodeResource.fetchModel({ id: message.id }) + return ContentNodeResource.retrieve(message.id) .then(contentNode => { return createReturnMsg({ message, data: contentNode }); }) @@ -228,12 +224,10 @@ } else { // limit to channel, defaults to true const limitToChannel = 'limitToChannel' in options ? options.limitToChannel : true; - searchPromise = ContentNodeResource.fetchCollection({ - getParams: { - search: keyword, - channels: limitToChannel ? this.topic.channel_id : undefined, - max_results: options.maxResults ? options.maxResults : 50, - }, + searchPromise = ContentNodeResource.list({ + search: keyword, + channels: limitToChannel ? this.topic.channel_id : undefined, + max_results: options.maxResults ? options.maxResults : 50, }).then(searchResults => { return { maxResults: options.maxResults ? options.maxResults : 50, @@ -258,7 +252,7 @@ navigateTo(message) { const id = message.nodeId; const context = {}; - return ContentNodeResource.fetchModel({ id }) + return ContentNodeResource.retrieve(id) .then(contentNode => { if (contentNode && contentNode.kind === 'topic') { router.push( @@ -323,14 +317,14 @@ return this.sandbox.mediator.sendMessage(newMsg); }, sendChannelFilterOptions(message) { - return ChannelResource.fetchFilterOptions(this.topic.channel_id) - .then(response => { + return ChannelResource.fetchFilterOptions_v2(this.topic.channel_id) + .then(filterOptions => { return createReturnMsg({ message, data: { - availableAuthors: response.data.available_authors, - availableTags: response.data.available_tags, - availableKinds: response.data.available_kinds, + availableAuthors: filterOptions.available_authors, + availableTags: filterOptions.available_tags, + availableKinds: filterOptions.available_kinds, }, }); }) @@ -348,16 +342,14 @@ // limit to channel, defaults to true const limitToChannel = 'limitToChannel' in options ? options.limitToChannel : true; - return ContentNodeResource.fetchRandomCollection({ - getParams: { - parent: options.parent === 'self' ? this.topic.id : options.parent, - channel_id: limitToChannel ? this.topic.channel_id : undefined, - max_results: options.maxResults ? options.maxResults : 10, - kind: onlyContent ? 'content' : undefined, - kind_in: kinds, - // Time seed to avoid cache - seed: Date.now().toString(), - }, + return ContentNodeResource.fetchRandomCollection_v2({ + parent: options.parent === 'self' ? this.topic.id : options.parent, + channel_id: limitToChannel ? this.topic.channel_id : undefined, + max_results: options.maxResults ? options.maxResults : 10, + kind: onlyContent ? 'content' : undefined, + kind_in: kinds, + // Time seed to avoid cache + seed: Date.now().toString(), }) .then(contentNodes => { return createReturnMsg({ diff --git a/kolibri/plugins/learn/frontend/views/CompletionModal/index.vue b/kolibri/plugins/learn/frontend/views/CompletionModal/index.vue index 450a24294f1..2529d09c97c 100644 --- a/kolibri/plugins/learn/frontend/views/CompletionModal/index.vue +++ b/kolibri/plugins/learn/frontend/views/CompletionModal/index.vue @@ -379,7 +379,7 @@ baseurl: this.baseurl, }, }; - return ContentNodeResource.fetchTree(treeParams).then(ancestor => { + return ContentNodeResource.fetchTree_v2(treeParams).then(ancestor => { let parent; if (fetchGrandparent) { parent = ancestor.children.results.find(c => c.id === this.contentNode.parent); @@ -392,7 +392,7 @@ }, loadRecommendedContent() { if (!this.baseurl) { - return ContentNodeResource.fetchRecommendationsFor(this.contentNodeId).then(data => { + return ContentNodeResource.fetchRecommendationsFor_v2(this.contentNodeId).then(data => { this.recommendedContentNodes = data; }); } diff --git a/kolibri/plugins/learn/frontend/views/ContentPage.vue b/kolibri/plugins/learn/frontend/views/ContentPage.vue index 02b57b49840..8528e341873 100644 --- a/kolibri/plugins/learn/frontend/views/ContentPage.vue +++ b/kolibri/plugins/learn/frontend/views/ContentPage.vue @@ -313,7 +313,7 @@ }, navigateTo(message) { const id = message.nodeId; - return ContentNodeResource.fetchModel({ id }) + return ContentNodeResource.retrieve(id) .then(contentNode => { router.push( this.genContentLinkKeepCurrentBackLink(contentNode.id, contentNode.is_leaf), diff --git a/kolibri/plugins/learn/frontend/views/CourseUnitView/__tests__/CourseUnitView.spec.js b/kolibri/plugins/learn/frontend/views/CourseUnitView/__tests__/CourseUnitView.spec.js index 41aa0045024..683a2b1ed57 100644 --- a/kolibri/plugins/learn/frontend/views/CourseUnitView/__tests__/CourseUnitView.spec.js +++ b/kolibri/plugins/learn/frontend/views/CourseUnitView/__tests__/CourseUnitView.spec.js @@ -20,7 +20,7 @@ jest.mock('kolibri-common/composables/usePreviousRoute', () => ({ jest.mock('../../../apiResources', () => ({ LearnerCourseResource: { getResumeData: jest.fn(), - fetchModel: jest.fn(), + retrieve: jest.fn(), }, })); @@ -122,7 +122,7 @@ describe('CourseUnitView', () => { useRouter.mockReturnValue(router); useRoute.mockReturnValue({ params: { courseId: 'course-1' } }); LearnerCourseResource.getResumeData.mockResolvedValue({}); - LearnerCourseResource.fetchModel.mockResolvedValue({ + LearnerCourseResource.retrieve.mockResolvedValue({ title: 'Test Course', course_id: COURSE_CONTENT_ID, }); @@ -135,8 +135,10 @@ describe('CourseUnitView', () => { const l1 = createLesson('l1', L1_TITLE, true, [r1, r2]); const l2 = createLesson('l2', L2_TITLE, false, [r3]); - ContentNodeResource.fetchTree.mockResolvedValue(createUnit('unit-1', UNIT_1_TITLE, [l1, l2])); - ContentNodeResource.fetchCollection.mockResolvedValue([ + ContentNodeResource.fetchTree_v2.mockResolvedValue( + createUnit('unit-1', UNIT_1_TITLE, [l1, l2]), + ); + ContentNodeResource.list.mockResolvedValue([ { id: UNIT_1, title: UNIT_1_TITLE, modality: 'UNIT' }, { id: UNIT_2, title: UNIT_2_TITLE, modality: 'UNIT' }, ]); @@ -155,7 +157,7 @@ describe('CourseUnitView', () => { } /** - * Mocks the unit tree returned by ContentNodeResource.fetchTree for the + * Mocks the unit tree returned by ContentNodeResource.fetchTree_v2 for the * redirect-guard tests that need a specific parent/child shape. * @param {object} [config] - Tree configuration. * @param {string} [config.unitId] - id of the unit at the root of the mocked tree. @@ -172,7 +174,7 @@ describe('CourseUnitView', () => { [LESSON_3]: [RESOURCE_3], }, } = {}) { - ContentNodeResource.fetchTree.mockResolvedValue({ + ContentNodeResource.fetchTree_v2.mockResolvedValue({ id: unitId, children: { results: lessonIds.map(lessonId => ({ @@ -529,7 +531,9 @@ describe('CourseUnitView', () => { const r3 = { ...createResource('r3', R3_TITLE, 'l2', 30), available: false }; const l1 = createLesson('l1', L1_TITLE, true, [r1, r2]); const l2 = createLesson('l2', L2_TITLE, false, [r3]); - ContentNodeResource.fetchTree.mockResolvedValue(createUnit('unit-1', UNIT_1_TITLE, [l1, l2])); + ContentNodeResource.fetchTree_v2.mockResolvedValue( + createUnit('unit-1', UNIT_1_TITLE, [l1, l2]), + ); mockResumeData({ resume_position: { unit_id: 'unit-1', lesson_id: 'l2', resource_id: 'r3' }, @@ -660,7 +664,9 @@ describe('CourseUnitView', () => { const r5 = createResource('r5', R5_TITLE, 'l2', 50); const l1 = createLesson('l1', L1_TITLE, true, [r1, r2, r3]); const l2 = createLesson('l2', L2_TITLE, false, [r4, r5]); - ContentNodeResource.fetchTree.mockResolvedValue(createUnit('unit-1', UNIT_1_TITLE, [l1, l2])); + ContentNodeResource.fetchTree_v2.mockResolvedValue( + createUnit('unit-1', UNIT_1_TITLE, [l1, l2]), + ); mockResumeData({ resume_position: { unit_id: 'unit-1', lesson_id: 'l1', resource_id: 'r3' }, diff --git a/kolibri/plugins/learn/frontend/views/CourseUnitView/index.vue b/kolibri/plugins/learn/frontend/views/CourseUnitView/index.vue index 566da262d8f..fc2ffbea8a2 100644 --- a/kolibri/plugins/learn/frontend/views/CourseUnitView/index.vue +++ b/kolibri/plugins/learn/frontend/views/CourseUnitView/index.vue @@ -152,14 +152,10 @@ const cameFromWelcome = ref(previousRoute?.value?.name === PageNames.COURSE_WELCOME); const fetchCourseWithUnits = async () => { - const courseData = await LearnerCourseResource.fetchModel({ - id: props.courseId, - }); - const unitsData = await ContentNodeResource.fetchCollection({ - getParams: { - parent: courseData.course_id, - modality: Modalities.UNIT, - }, + const courseData = await LearnerCourseResource.retrieve(props.courseId); + const unitsData = await ContentNodeResource.list({ + parent: courseData.course_id, + modality: Modalities.UNIT, }); return { course: courseData, @@ -183,7 +179,7 @@ fetchData: fetchUnitTreeData, } = useFetch({ fetchMethod: () => - ContentNodeResource.fetchTree({ + ContentNodeResource.fetchTree_v2({ id: props.unitId, // Include unavailable nodes so missing resources show a // warning in the navigation panel instead of disappearing. diff --git a/kolibri/plugins/learn/frontend/views/DeviceConnectionStatus.vue b/kolibri/plugins/learn/frontend/views/DeviceConnectionStatus.vue index 0d2f768386f..04169dc86b2 100644 --- a/kolibri/plugins/learn/frontend/views/DeviceConnectionStatus.vue +++ b/kolibri/plugins/learn/frontend/views/DeviceConnectionStatus.vue @@ -41,10 +41,10 @@ const isFetched = ref(false); const allDevices = ref([]); const getStudio = async () => { - const response = await RemoteChannelResource.getKolibriStudioStatus(); + const studioStatus = await RemoteChannelResource.getKolibriStudioStatus_v2(); set(allDevices, [ { - ...response.data, + ...studioStatus, id: KolibriStudioId, instance_id: KolibriStudioId, }, diff --git a/kolibri/plugins/learn/frontend/views/ExamPage/index.vue b/kolibri/plugins/learn/frontend/views/ExamPage/index.vue index 557c57d8ec8..98fd59f1fdf 100644 --- a/kolibri/plugins/learn/frontend/views/ExamPage/index.vue +++ b/kolibri/plugins/learn/frontend/views/ExamPage/index.vue @@ -327,7 +327,6 @@ import ResourceSyncingUiAlert from '../ResourceSyncingUiAlert'; import useProgressTracking from '../../composables/useProgressTracking'; import { PageNames, ClassesPageNames } from '../../constants'; - import { LearnerClassroomResource } from '../../apiResources'; import AnswerHistory from './AnswerHistory'; export default { @@ -612,10 +611,6 @@ this.goToQuestion(opt.value); }, setAndSaveCurrentExamAttemptLog({ close, interaction } = {}) { - // Clear the learner classroom cache here as its progress data is now - // stale - LearnerClassroomResource.clearCache(); - const data = {}; if (interaction) { diff --git a/kolibri/plugins/learn/frontend/views/LearnIndex.vue b/kolibri/plugins/learn/frontend/views/LearnIndex.vue index 26c4b74bb7b..16f6f2793af 100644 --- a/kolibri/plugins/learn/frontend/views/LearnIndex.vue +++ b/kolibri/plugins/learn/frontend/views/LearnIndex.vue @@ -52,7 +52,7 @@ if (!picturePasswordPending.value) return; const [user] = await Promise.all([ - FacilityUserResource.fetchModel({ id: get(currentUserId) }), + FacilityUserResource.retrieve(get(currentUserId)), fetchFacilityConfig(), ]); diff --git a/kolibri/plugins/learn/frontend/views/LibraryPage/index.vue b/kolibri/plugins/learn/frontend/views/LibraryPage/index.vue index 4055f50995b..a6d11e32137 100644 --- a/kolibri/plugins/learn/frontend/views/LibraryPage/index.vue +++ b/kolibri/plugins/learn/frontend/views/LibraryPage/index.vue @@ -299,12 +299,10 @@ fetchResumableContentNodes(); } const shouldResolve = samePageCheckGenerator(); - return ContentNodeResource.fetchCollection({ - getParams: { - parent__isnull: true, - include_coach_content: get(hasRole), - baseurl, - }, + return ContentNodeResource.list({ + parent__isnull: true, + include_coach_content: get(hasRole), + baseurl, }).then( channelCollection => { if (shouldResolve()) { diff --git a/kolibri/plugins/learn/frontend/views/QuizRenderer/index.vue b/kolibri/plugins/learn/frontend/views/QuizRenderer/index.vue index 0044284e7de..bbdc20ce8e4 100644 --- a/kolibri/plugins/learn/frontend/views/QuizRenderer/index.vue +++ b/kolibri/plugins/learn/frontend/views/QuizRenderer/index.vue @@ -179,7 +179,6 @@ import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow'; import commonCoreStrings from 'kolibri/uiText/commonCoreStrings'; import shuffled from 'kolibri-common/utils/shuffled'; - import { LearnerClassroomResource } from '../../apiResources'; import AnswerHistory from './AnswerHistory'; import QuizReport from './QuizReport'; @@ -374,10 +373,6 @@ }, methods: { setAndSaveCurrentExamAttemptLog({ close, interaction } = {}) { - // Clear the learner classroom cache here as its progress data is now - // stale - LearnerClassroomResource.clearCache(); - const data = {}; if (interaction) { diff --git a/kolibri/plugins/learn/frontend/views/TopicsContentPage.vue b/kolibri/plugins/learn/frontend/views/TopicsContentPage.vue index 1b3dc32f332..671a7a6e2ec 100644 --- a/kolibri/plugins/learn/frontend/views/TopicsContentPage.vue +++ b/kolibri/plugins/learn/frontend/views/TopicsContentPage.vue @@ -257,7 +257,7 @@ function _loadTopicsContent(shouldResolve, baseurl) { const id = props.id; return Promise.all([ - ContentNodeResource.fetchModel({ id, getParams: { baseurl } }), + ContentNodeResource.retrieve(id, { params: { baseurl } }), fetchChannels({ baseurl }), ]).then( ([fetchedContent]) => { @@ -326,7 +326,7 @@ fetchContentNodeTreeProgress(more); } // Fetch additional content nodes - return ContentNodeResource.fetchTree(more) + return ContentNodeResource.fetchTree_v2(more) .then(({ children }) => { viewResourcesContents.value = [...viewResourcesContents.value, ...children.results]; moreResourcesContentAvailable.value = children.more; @@ -637,7 +637,7 @@ if (this.isUserLoggedIn && !this.baseurl) { this.fetchContentNodeTreeProgress(treeParams); } - return ContentNodeResource.fetchTree(treeParams).then(ancestor => { + return ContentNodeResource.fetchTree_v2(treeParams).then(ancestor => { let parent; let nextFolders; if (fetchGrandparent) { diff --git a/kolibri/plugins/learn/frontend/views/TopicsPage/index.vue b/kolibri/plugins/learn/frontend/views/TopicsPage/index.vue index 933435a6bcb..55f9eb2790f 100644 --- a/kolibri/plugins/learn/frontend/views/TopicsPage/index.vue +++ b/kolibri/plugins/learn/frontend/views/TopicsPage/index.vue @@ -441,7 +441,7 @@ fetchContentNodeTreeProgress({ id, params }); } return Promise.all([ - ContentNodeResource.fetchTree({ + ContentNodeResource.fetchTree_v2({ id, params, }), @@ -783,7 +783,7 @@ if (this.isUserLoggedIn && !this.deviceId) { this.fetchContentNodeTreeProgress(more); } - return ContentNodeResource.fetchTree(more) + return ContentNodeResource.fetchTree_v2(more) .then(data => { const child = this.contents[parentIndex]; child.children.results = child.children.results.concat(data.children.results); @@ -813,7 +813,7 @@ if (this.isUserLoggedIn && !this.deviceId) { this.fetchContentNodeTreeProgress(more); } - return ContentNodeResource.fetchTree(more) + return ContentNodeResource.fetchTree_v2(more) .then(data => { this.contents = this.contents.concat(data.children.results); this.topic = { diff --git a/kolibri/plugins/learn/frontend/views/__tests__/BookmarkPage.spec.js b/kolibri/plugins/learn/frontend/views/__tests__/BookmarkPage.spec.js index 8158179b95b..810388c5107 100644 --- a/kolibri/plugins/learn/frontend/views/__tests__/BookmarkPage.spec.js +++ b/kolibri/plugins/learn/frontend/views/__tests__/BookmarkPage.spec.js @@ -17,7 +17,7 @@ describe('Bookmark Page', () => { const fakeBookmarks = [{ bookmark: { id: 1 } }, { bookmark: { id: 2 } }, { bookmark: { id: 3 } }]; beforeEach(async () => { - ContentNodeResource.fetchBookmarks.mockResolvedValue({ + ContentNodeResource.fetchBookmarks_v2.mockResolvedValue({ results: fakeBookmarks, more: { available: true, limit: 25 }, }); @@ -46,7 +46,7 @@ describe('Bookmark Page', () => { expect(wrapper.find("[data-testid='load-more-button']")).toBeTruthy(); }); it('clicking the load more button calls the load more function', async () => { - const mockFetchBookmarks = ContentNodeResource.fetchBookmarks.mockResolvedValue({ + const mockFetchBookmarks = ContentNodeResource.fetchBookmarks_v2.mockResolvedValue({ results: fakeBookmarks, }); await wrapper.find("[data-testid='load-more-button']").vm.$emit('click'); diff --git a/kolibri/plugins/learn/frontend/views/__tests__/BrowseResourceMetadata.spec.js b/kolibri/plugins/learn/frontend/views/__tests__/BrowseResourceMetadata.spec.js index 2c8d8763e03..32f379c1bbc 100644 --- a/kolibri/plugins/learn/frontend/views/__tests__/BrowseResourceMetadata.spec.js +++ b/kolibri/plugins/learn/frontend/views/__tests__/BrowseResourceMetadata.spec.js @@ -29,8 +29,8 @@ jest.mock('kolibri-plugin-data', () => { const promise = new Promise(() => []); -ContentNodeResource.fetchRecommendationsFor = jest.fn(() => promise); -ContentNodeResource.fetchCollection = jest.fn(() => promise); +ContentNodeResource.fetchRecommendationsFor_v2 = jest.fn(() => promise); +ContentNodeResource.list = jest.fn(() => promise); const baseContentNode = { id: '2ea9bda8703241be89b5b9fd87f88815', diff --git a/kolibri/plugins/learn/frontend/views/__tests__/LearnIndex.spec.js b/kolibri/plugins/learn/frontend/views/__tests__/LearnIndex.spec.js index 24300a5c12e..5ef8f0af4d1 100644 --- a/kolibri/plugins/learn/frontend/views/__tests__/LearnIndex.spec.js +++ b/kolibri/plugins/learn/frontend/views/__tests__/LearnIndex.spec.js @@ -9,7 +9,7 @@ import LearnIndex from '../LearnIndex'; jest.mock('kolibri-common/composables/useFacility'); jest.mock('kolibri/composables/useUser'); jest.mock('kolibri-common/apiResources/FacilityUserResource', () => ({ - fetchModel: jest.fn(), + retrieve: jest.fn(), })); async function flushUi() { @@ -40,7 +40,7 @@ describe('LearnIndex picture password modal', () => { it('shows the modal and keeps the flag set while the modal is open', async () => { sessionStorage.setItem(PICTURE_PASSWORD_ASSIGNED_MODAL_PENDING, 'true'); - FacilityUserResource.fetchModel.mockResolvedValue({ picture_password: '3.7.12' }); + FacilityUserResource.retrieve.mockResolvedValue({ picture_password: '3.7.12' }); renderComponent(); await flushUi(); @@ -51,7 +51,7 @@ describe('LearnIndex picture password modal', () => { it('clears the flag when the modal is dismissed', async () => { sessionStorage.setItem(PICTURE_PASSWORD_ASSIGNED_MODAL_PENDING, 'true'); - FacilityUserResource.fetchModel.mockResolvedValue({ picture_password: '3.7.12' }); + FacilityUserResource.retrieve.mockResolvedValue({ picture_password: '3.7.12' }); renderComponent(); await flushUi(); @@ -68,7 +68,7 @@ describe('LearnIndex picture password modal', () => { it('does not show the modal when picture_password is null', async () => { sessionStorage.setItem(PICTURE_PASSWORD_ASSIGNED_MODAL_PENDING, 'true'); - FacilityUserResource.fetchModel.mockResolvedValue({ picture_password: null }); + FacilityUserResource.retrieve.mockResolvedValue({ picture_password: null }); renderComponent(); await flushUi(); @@ -78,7 +78,7 @@ describe('LearnIndex picture password modal', () => { it('keeps the flag set when picture_password is null but facility has picture passwords enabled', async () => { sessionStorage.setItem(PICTURE_PASSWORD_ASSIGNED_MODAL_PENDING, 'true'); - FacilityUserResource.fetchModel.mockResolvedValue({ picture_password: null }); + FacilityUserResource.retrieve.mockResolvedValue({ picture_password: null }); renderComponent({ facilityConfig: ref({ picture_password_settings: { icon_style: 'standard' } }), @@ -91,7 +91,7 @@ describe('LearnIndex picture password modal', () => { it('clears the flag when picture_password is null and user is not a learner, even if facility has picture passwords enabled', async () => { sessionStorage.setItem(PICTURE_PASSWORD_ASSIGNED_MODAL_PENDING, 'true'); - FacilityUserResource.fetchModel.mockResolvedValue({ picture_password: null }); + FacilityUserResource.retrieve.mockResolvedValue({ picture_password: null }); renderComponent({ facilityConfig: ref({ picture_password_settings: { icon_style: 'standard' } }), @@ -104,12 +104,12 @@ describe('LearnIndex picture password modal', () => { }); it('does not fetch user data when the flag is not set', async () => { - FacilityUserResource.fetchModel.mockResolvedValue({ picture_password: '3.7.12' }); + FacilityUserResource.retrieve.mockResolvedValue({ picture_password: '3.7.12' }); renderComponent(); await flushUi(); - expect(FacilityUserResource.fetchModel).not.toHaveBeenCalled(); + expect(FacilityUserResource.retrieve).not.toHaveBeenCalled(); expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); }); }); diff --git a/kolibri/plugins/learn/frontend/views/__tests__/LibraryPage.spec.js b/kolibri/plugins/learn/frontend/views/__tests__/LibraryPage.spec.js index 98a40ab4f9d..ea9f081f394 100644 --- a/kolibri/plugins/learn/frontend/views/__tests__/LibraryPage.spec.js +++ b/kolibri/plugins/learn/frontend/views/__tests__/LibraryPage.spec.js @@ -90,7 +90,7 @@ describe('LibraryPage', () => { fetchChannels: jest.fn(() => Promise.resolve([CHANNEL])), }), ); - ContentNodeResource.fetchCollection.mockImplementation(() => + ContentNodeResource.list.mockImplementation(() => Promise.resolve([{ id: 'test', title: 'test', channel_id: CHANNEL_ID }]), ); }); diff --git a/kolibri/plugins/learn/frontend/views/__tests__/TopicsContentPage.spec.js b/kolibri/plugins/learn/frontend/views/__tests__/TopicsContentPage.spec.js index ccbed9ecd72..3103c90738a 100644 --- a/kolibri/plugins/learn/frontend/views/__tests__/TopicsContentPage.spec.js +++ b/kolibri/plugins/learn/frontend/views/__tests__/TopicsContentPage.spec.js @@ -52,8 +52,8 @@ async function makeWrapper({ isUserLoggedIn = false, } = {}) { const store = makeStore(); - ContentNodeResource.fetchCollection.mockResolvedValue([]); - ContentNodeResource.fetchModel.mockResolvedValue({ + ContentNodeResource.list.mockResolvedValue([]); + ContentNodeResource.retrieve.mockResolvedValue({ id: CONTENT_ID, admin_imported: isContentAdminImported, channel_id: CHANNEL_ID, diff --git a/kolibri/plugins/learn/frontend/views/__tests__/TopicsPage.spec.js b/kolibri/plugins/learn/frontend/views/__tests__/TopicsPage.spec.js index b3deea4df18..fbb1217b1ab 100644 --- a/kolibri/plugins/learn/frontend/views/__tests__/TopicsPage.spec.js +++ b/kolibri/plugins/learn/frontend/views/__tests__/TopicsPage.spec.js @@ -138,7 +138,7 @@ describe('TopicsPage', () => { }), ); - ContentNodeResource.fetchTree.mockResolvedValue(DEFAULT_TOPIC); + ContentNodeResource.fetchTree_v2.mockResolvedValue(DEFAULT_TOPIC); store = makeStore({}); useDevicesWithFilter.mockReturnValue({ @@ -163,7 +163,7 @@ describe('TopicsPage', () => { windowBreakpoint: ref(4), })); - ContentNodeResource.fetchTree.mockResolvedValue({ + ContentNodeResource.fetchTree_v2.mockResolvedValue({ ...DEFAULT_TOPIC, options: { modality: 'CUSTOM_NAVIGATION' }, }); @@ -346,7 +346,7 @@ describe('TopicsPage', () => { }), ); - ContentNodeResource.fetchTree.mockResolvedValue(DEFAULT_TOPIC); + ContentNodeResource.fetchTree_v2.mockResolvedValue(DEFAULT_TOPIC); useKResponsiveWindow.mockImplementation(() => ({ windowIsSmall: true, @@ -461,7 +461,7 @@ describe('TopicsPage', () => { }); it('shows correct breadcrumbs at a non-Channel Topic', async () => { - ContentNodeResource.fetchTree.mockResolvedValue(DEFAULT_TOPIC.children.results[0]); + ContentNodeResource.fetchTree_v2.mockResolvedValue(DEFAULT_TOPIC.children.results[0]); useBaseSearch.mockImplementation(() => useBaseSearchMock({ displayingSearchResults: false, diff --git a/kolibri/plugins/learn/frontend/views/classes/ClassAssignmentsPage.vue b/kolibri/plugins/learn/frontend/views/classes/ClassAssignmentsPage.vue index cce227fdb74..33b63595c03 100644 --- a/kolibri/plugins/learn/frontend/views/classes/ClassAssignmentsPage.vue +++ b/kolibri/plugins/learn/frontend/views/classes/ClassAssignmentsPage.vue @@ -82,10 +82,7 @@ const activeLessons = computed(() => getClassActiveLessons(classId.value)); const activeQuizzes = computed(() => getClassActiveQuizzes(classId.value)); - const polling = useTimeoutPoll( - () => fetchClass({ classId: classId.value, force: true }), - 30000, - ); + const polling = useTimeoutPoll(() => fetchClass({ classId: classId.value }), 30000); polling.resume(); onBeforeUnmount(polling.pause); diff --git a/kolibri/plugins/learn/frontend/views/courses/PrePostTestRenderer/index.vue b/kolibri/plugins/learn/frontend/views/courses/PrePostTestRenderer/index.vue index c9114596e85..aa1b7ea9ad2 100644 --- a/kolibri/plugins/learn/frontend/views/courses/PrePostTestRenderer/index.vue +++ b/kolibri/plugins/learn/frontend/views/courses/PrePostTestRenderer/index.vue @@ -164,7 +164,6 @@ import get from 'lodash/get'; import { coursesStrings } from 'kolibri-common/strings/coursesStrings.js'; import shuffled from 'kolibri-common/utils/shuffled'; - import { LearnerClassroomResource } from '../../../apiResources'; import ResourceLayout from '../../ResourceLayout/index.vue'; import CourseInterstitial from '../../CourseUnitView/CourseInterstitial.vue'; import { PRE_POST_TEST_CRITERION, TestType } from '../../../constants'; @@ -369,10 +368,6 @@ }, methods: { setAndSaveCurrentExamAttemptLog({ close, interaction } = {}) { - // Clear the learner classroom cache here as its progress data is now - // stale - LearnerClassroomResource.clearCache(); - const data = {}; if (interaction) { diff --git a/kolibri/plugins/learn/frontend/views/courses/QuizRenderer/index.vue b/kolibri/plugins/learn/frontend/views/courses/QuizRenderer/index.vue index d001ddba8ef..ad91704d89b 100644 --- a/kolibri/plugins/learn/frontend/views/courses/QuizRenderer/index.vue +++ b/kolibri/plugins/learn/frontend/views/courses/QuizRenderer/index.vue @@ -159,7 +159,6 @@ import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow'; import commonCoreStrings from 'kolibri/uiText/commonCoreStrings'; import shuffled from 'kolibri-common/utils/shuffled'; - import { LearnerClassroomResource } from '../../../apiResources'; import ResourceLayout from '../../ResourceLayout/index.vue'; import AnswerHistory from './AnswerHistory'; import QuizReport from './QuizReport'; @@ -321,10 +320,6 @@ }, methods: { setAndSaveCurrentExamAttemptLog({ close, interaction } = {}) { - // Clear the learner classroom cache here as its progress data is now - // stale - LearnerClassroomResource.clearCache(); - const data = {}; if (interaction) { diff --git a/packages/kolibri-common/apiResources/ChannelResource.js b/packages/kolibri-common/apiResources/ChannelResource.js index 8c2fcc9f89f..a1eac267b3e 100644 --- a/packages/kolibri-common/apiResources/ChannelResource.js +++ b/packages/kolibri-common/apiResources/ChannelResource.js @@ -11,4 +11,9 @@ export default new Resource({ fetchFilterOptions(id) { return this.getListEndpoint('filter_options', { id }); }, + // Unlike `fetchFilterOptions`, resolves with `response.data`, not the whole response. + async fetchFilterOptions_v2(id) { + const { data } = await this.request({ action: 'filter_options', params: { id } }); + return data; + }, }); diff --git a/packages/kolibri-common/apiResources/ContentNodeProgressResource.js b/packages/kolibri-common/apiResources/ContentNodeProgressResource.js index ffd770bd739..f9e96eb36fe 100644 --- a/packages/kolibri-common/apiResources/ContentNodeProgressResource.js +++ b/packages/kolibri-common/apiResources/ContentNodeProgressResource.js @@ -17,4 +17,8 @@ export default new Resource({ return response.data; }); }, + async fetchTree_v2({ id, params }) { + const { data } = await this.request({ action: 'tree', routeParams: id, params }); + return data; + }, }); diff --git a/packages/kolibri-common/apiResources/ContentNodeResource.js b/packages/kolibri-common/apiResources/ContentNodeResource.js index cfef7241c4b..3444990286e 100644 --- a/packages/kolibri-common/apiResources/ContentNodeResource.js +++ b/packages/kolibri-common/apiResources/ContentNodeResource.js @@ -85,6 +85,11 @@ export default new Resource({ fetchRandomCollection({ getParams: params }) { return this.getListEndpoint('random', params); }, + // Unlike `fetchRandomCollection`, takes plain params and resolves with `response.data`. + async fetchRandomCollection_v2(params) { + const { data } = await this.request({ action: 'random', params }); + return data; + }, fetchDescendantsAssessments(ids) { return this.getListEndpoint('descendants_assessments', { ids }); }, @@ -95,6 +100,10 @@ export default new Resource({ fetchRecommendationsFor(id, getParams) { return this.fetchDetailCollection('recommendations_for', id, getParams); }, + async fetchRecommendationsFor_v2(id, params) { + const { data } = await this.request({ action: 'recommendations_for', routeParams: id, params }); + return data; + }, fetchResume(params = { resume: true }) { const url = urls['kolibri:core:usercontentnode_list'](); return this.client({ url, params }).then(response => { diff --git a/packages/kolibri-common/apiResources/RemoteChannelResource.js b/packages/kolibri-common/apiResources/RemoteChannelResource.js index 31a369ff1b3..b1f8aee0575 100644 --- a/packages/kolibri-common/apiResources/RemoteChannelResource.js +++ b/packages/kolibri-common/apiResources/RemoteChannelResource.js @@ -5,4 +5,9 @@ export default new Resource({ getKolibriStudioStatus() { return this.getListEndpoint('kolibri_studio_status'); }, + // Unlike `getKolibriStudioStatus`, resolves with `response.data`, not the whole response. + async getKolibriStudioStatus_v2() { + const { data } = await this.request({ action: 'kolibri_studio_status' }); + return data; + }, });