Skip to content

Commit

Permalink
pagination on fetch channels, playlists and videos
Browse files Browse the repository at this point in the history
  • Loading branch information
ruturaj-kalal committed Nov 12, 2023
1 parent 3ef4765 commit f2606b9
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,43 @@ function getChannelListFun()
}
var htmlError = '<div id="saErroroauthRegister">Something went wrong.</div>';
var service:Service =restService.getChannelListService;
service.URL += '/api/bus/'+businessId+'/channels/';
var result:Result = service.call({
'Method':"GET",
'token':getAccessToken
});
if (result.isOk()) {
var htmlSuccess = result.getObject().toString();
return htmlSuccess;
} else {
var resultMessage = JSON.parse(result.errorMessage);
ISML.renderTemplate('dashboard/errorMsg',{errorMsg:resultMessage});
return;
}
var allChannels = [];
var nextPageUrl = '/api/bus/'+businessId+'/channels/';
var originalURL = service.URL;

do {

service.URL = originalURL + nextPageUrl;
var result:Result = service.call({
'Method':"GET",
'token':getAccessToken
});

if (result.isOk()) {
var response = JSON.parse(result.getObject().toString());
if (response.channels && Array.isArray(response.channels)) {
allChannels = allChannels.concat(response.channels);
}

// Check if there is a next page
if (response.paging && response.paging.next) {
nextPageUrl = response.paging.next;
} else {
nextPageUrl = null;
}
} else {
var resultMessage = JSON.parse(result.errorMessage);
ISML.renderTemplate('dashboard/errorMsg',{errorMsg:resultMessage});
return;
}

}while(nextPageUrl);

var combinedChannels = {
channels: allChannels
};

return JSON.stringify(combinedChannels);
}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,42 @@ function getChannelPlayListFun(ChannelId)
var businessId=businessOauthData.businessId;
var getAccessToken=oauthtokenData.access_token;
}
var htmlError = '<div id="saErroroauthRegister">Something went wrong.</div>';
var service:Service =restService.getChannelPlaylistService;
service.URL += '/api/bus/'+businessId+'/channels/'+ChannelId+'/playlists';
var result:Result = service.call({
'Method':"GET",
'token':getAccessToken
});
if (result.isOk()) {
var htmlSuccess = result.getObject().toString();
return htmlSuccess;
} else {
var resultMessage = JSON.parse(result.errorMessage);
ISML.renderTemplate('dashboard/errorMsg',{errorMsg:resultMessage});
return;
}
var htmlError = '<div id="saErroroauthRegister">Something went wrong.</div>';
var service:Service =restService.getChannelPlaylistService;
var allPlaylists = [];
var nextPageUrl = '/api/bus/'+businessId+'/channels/'+ChannelId+'/playlists';
var originalURL = service.URL;

do {
service.URL = originalURL + nextPageUrl;
var result = service.call({
'Method': "GET",
'token': getAccessToken
});

if (result.isOk()) {
var response = JSON.parse(result.getObject().toString());
if (response.playlists && Array.isArray(response.playlists)) {
allPlaylists = allPlaylists.concat(response.playlists);
}
// Check if there is a next page
if (response.paging && response.paging.next) {
nextPageUrl = response.paging.next;
} else {
nextPageUrl = null;
}
} else {
var resultMessage = JSON.parse(result.errorMessage);
ISML.renderTemplate('dashboard/errorMsg',{errorMsg:resultMessage});
return;
}
} while (nextPageUrl);

var combinedPlaylists = {
playlists: allPlaylists
};

return JSON.stringify(combinedPlaylists);
}
module.exports = {
getChannelPlayListFun: getChannelPlayListFun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,45 @@ function getChannelVideoFun(ChannelId,playlistID)
var service:Service =restService.getChannelVideoService;
if(playlistID)
{
service.URL += '/api/bus/'+businessId+'/channels/'+ChannelId+'/playlists/'+playlistID+'/videos';
var nextPageUrl = '/api/bus/'+businessId+'/channels/'+ChannelId+'/playlists/'+playlistID+'/videos';
}
else
{
service.URL += '/api/bus/'+businessId+'/videos?channel_id='+ChannelId;
var nextPageUrl = '/api/bus/'+businessId+'/videos?channel_id='+ChannelId;
}
var result:Result = service.call({
'Method':"GET",
'token':getAccessToken
});
if (result.isOk()) {
var htmlSuccess = result.getObject().toString();
return htmlSuccess;
} else {
var resultMessage = JSON.parse(result.errorMessage);
ISML.renderTemplate('dashboard/errorMsg',{errorMsg:resultMessage});
return;
}
var allVideos = [];
var originalURL = service.URL;

do {
service.URL = originalURL + nextPageUrl;
var result:Result = service.call({
'Method':"GET",
'token':getAccessToken
});
if (result.isOk()) {
var response = JSON.parse(result.getObject().toString());
if (response.videos && Array.isArray(response.videos)) {
allVideos = allVideos.concat(response.videos);
}

// Check if there is a next page
if (response.paging && response.paging.next) {
nextPageUrl = response.paging.next;
} else {
nextPageUrl = null;
}
} else {
var resultMessage = JSON.parse(result.errorMessage);
ISML.renderTemplate('dashboard/errorMsg',{errorMsg:resultMessage});
return;
}
} while(nextPageUrl);

var combinedVideos = {
videos: allVideos
};

return JSON.stringify(combinedVideos);
}

module.exports = {
Expand Down

0 comments on commit f2606b9

Please sign in to comment.