From e27703f1b035c61038849a99ac3bb222fa877b89 Mon Sep 17 00:00:00 2001 From: curvesy Date: Sun, 25 Jun 2023 20:33:02 +0330 Subject: [PATCH 1/4] Return audios by collectionID --- services/gateway/apis/http-version3/methods/audios.js | 1 + 1 file changed, 1 insertion(+) diff --git a/services/gateway/apis/http-version3/methods/audios.js b/services/gateway/apis/http-version3/methods/audios.js index 896f08588..e1d1eed73 100644 --- a/services/gateway/apis/http-version3/methods/audios.js +++ b/services/gateway/apis/http-version3/methods/audios.js @@ -11,6 +11,7 @@ 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 }, }, get schema() { const audioSchema = {}; From 2ed9c913d69e4ecc03e1a46f0dff3a5614b9ccef Mon Sep 17 00:00:00 2001 From: curvesy Date: Mon, 26 Jun 2023 16:35:01 +0330 Subject: [PATCH 2/4] Return audios by ownerAddress --- .../shared/dataService/business/audios.js | 33 ++++++++++++++++--- .../apis/http-version3/methods/audios.js | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/services/blockchain-indexer/shared/dataService/business/audios.js b/services/blockchain-indexer/shared/dataService/business/audios.js index d1f6b14bc..30785b9c6 100644 --- a/services/blockchain-indexer/shared/dataService/business/audios.js +++ b/services/blockchain-indexer/shared/dataService/business/audios.js @@ -41,11 +41,34 @@ 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'], + ); + audioData = await BluebirdPromise.map( + audioIDs, + 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, diff --git a/services/gateway/apis/http-version3/methods/audios.js b/services/gateway/apis/http-version3/methods/audios.js index e1d1eed73..235fae4df 100644 --- a/services/gateway/apis/http-version3/methods/audios.js +++ b/services/gateway/apis/http-version3/methods/audios.js @@ -12,6 +12,7 @@ module.exports = { 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 = {}; From fd68a2c05b40b14d7b12f6cc747a95fad923bc00 Mon Sep 17 00:00:00 2001 From: curvesy Date: Tue, 27 Jun 2023 16:04:16 +0330 Subject: [PATCH 3/4] Filter owner audios based on share greater than zero and fix the test issue --- .../shared/dataService/business/audios.js | 7 +++++-- services/gateway/tests/constants/generateDocs.js | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/blockchain-indexer/shared/dataService/business/audios.js b/services/blockchain-indexer/shared/dataService/business/audios.js index 30785b9c6..fe067d067 100644 --- a/services/blockchain-indexer/shared/dataService/business/audios.js +++ b/services/blockchain-indexer/shared/dataService/business/audios.js @@ -47,10 +47,13 @@ const getAudios = async (params = {}) => { // audiosID const audioIDs = await ownersTable.find( { address: params.ownerAddress }, - ['audioID'], + ['audioID', 'shares'], ); + + const filteredAudioIDs = audioIDs.filter(audio => audio.shares > 0); + audioData = await BluebirdPromise.map( - audioIDs, + filteredAudioIDs, async (audioID) => { const audio = await audiosTable.find( { audioID: audioID.audioID }, diff --git a/services/gateway/tests/constants/generateDocs.js b/services/gateway/tests/constants/generateDocs.js index cf57676dd..c65783f41 100644 --- a/services/gateway/tests/constants/generateDocs.js +++ b/services/gateway/tests/constants/generateDocs.js @@ -24,6 +24,12 @@ const createApiDocsExpectedResponse = { { $ref: '#/parameters/audioID', }, + { + $ref: '#/parameters/collectionID', + }, + { + $ref: '#/parameters/ownerAddress', + }, ], responses: { 200: { From a8d1cb9fa4ac38ee62e4ed5f5e88507f1728b9f9 Mon Sep 17 00:00:00 2001 From: Ali Haghighatkhah Date: Tue, 4 Jul 2023 20:46:46 +0200 Subject: [PATCH 4/4] Fix concurrency condition --- .../blockchain-indexer/shared/dataService/business/audios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/blockchain-indexer/shared/dataService/business/audios.js b/services/blockchain-indexer/shared/dataService/business/audios.js index fe067d067..ac7c9e22a 100644 --- a/services/blockchain-indexer/shared/dataService/business/audios.js +++ b/services/blockchain-indexer/shared/dataService/business/audios.js @@ -62,7 +62,7 @@ const getAudios = async (params = {}) => { return audio[0]; }, - { concurrency: audioIDs.length }, + { concurrency: filteredAudioIDs.length }, ); } else { audioData = await audiosTable.find(