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

Return audios by collectionID and ownerAddress #49

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions services/blockchain-indexer/shared/dataService/business/audios.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,37 @@ const getAudios = async (params = {}) => {
const ownersTable = await getOwnersIndex();
const featsTable = await getFeatsIndex();

const total = await audiosTable.count(params);
const audioData = await audiosTable.find(
{ ...params, limit: params.limit || total },
['audioID', 'creatorAddress', 'name', 'releaseYear', 'collectionID'],
);
let audioData = [];

if (params.ownerAddress) {
// audiosID
const audioIDs = await ownersTable.find(
{ address: params.ownerAddress },
['audioID', 'shares'],
);

const filteredAudioIDs = audioIDs.filter(audio => audio.shares > 0);

audioData = await BluebirdPromise.map(
filteredAudioIDs,
async (audioID) => {
const audio = await audiosTable.find(
{ audioID: audioID.audioID },
['audioID', 'creatorAddress', 'name', 'releaseYear', 'collectionID'],
);

return audio[0];
},
{ concurrency: audioIDs.length },
);
} else {
audioData = await audiosTable.find(
{ ...params, limit: params.limit },
['audioID', 'creatorAddress', 'name', 'releaseYear', 'collectionID'],
);
}

const total = audioData.length;

const data = await BluebirdPromise.map(
audioData,
Expand Down
2 changes: 2 additions & 0 deletions services/gateway/apis/http-version3/methods/audios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module.exports = {
params: {
creatorAddress: { optional: true, type: 'string', min: 3, max: 41, pattern: regex.ADDRESS_LISK32 },
audioID: { optional: true, type: 'string', min: 1, max: 64, pattern: regex.HASH_SHA256 },
collectionID: { optional: true, type: 'string', min: 1, max: 64, pattern: regex.HASH_SHA256 },
ownerAddress: { optional: true, type: 'string', min: 3, max: 41, pattern: regex.ADDRESS_LISK32 },
},
get schema() {
const audioSchema = {};
Expand Down
6 changes: 6 additions & 0 deletions services/gateway/tests/constants/generateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const createApiDocsExpectedResponse = {
{
$ref: '#/parameters/audioID',
},
{
$ref: '#/parameters/collectionID',
},
{
$ref: '#/parameters/ownerAddress',
},
],
responses: {
200: {
Expand Down