Skip to content

Commit

Permalink
RC #293 - Updating project_ids search parameter format
Browse files Browse the repository at this point in the history
  • Loading branch information
dleadbetter committed Jul 28, 2024
1 parent d69c32b commit 8362f3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
22 changes: 11 additions & 11 deletions packages/core-data/src/services/BaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchOne(id, params = {}) {
const url = Api.buildUrl(this.baseUrl, this.getRoute(), id, this.getSearchParams(params));
const url = Api.buildUrl(this.baseUrl, this.getRoute(), id, this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -38,7 +38,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedEvents(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'events', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'events', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -51,7 +51,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedInstances(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'instances', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'instances', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -64,7 +64,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedItems(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'items', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'items', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -77,7 +77,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedManifests(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'manifests', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'manifests', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -90,7 +90,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedMedia(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'media_contents', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'media_contents', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -103,7 +103,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedOrganizations(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'organizations', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'organizations', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -115,7 +115,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedPeople(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'people', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'people', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -128,7 +128,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedPlaces(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'places', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'places', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -141,7 +141,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedTaxonomies(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'taxonomies', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'taxonomies', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand All @@ -154,7 +154,7 @@ class BaseService {
* @returns {Promise<any>}
*/
fetchRelatedWorks(id, params = {}) {
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'works', this.getSearchParams(params));
const url = Api.buildNestedUrl(this.baseUrl, this.getRoute(), id, 'works', this.projectIds, params);
return fetch(url).then((response) => response.json());
}

Expand Down
16 changes: 14 additions & 2 deletions packages/core-data/src/utils/Api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
// @flow

import _ from 'underscore';

/**
* Builds a fully qualified nested URL for the passed base URL and route.
*
* @param baseUrl
* @param route
* @param id
* @param nested
* @params projectIds
* @param searchParams
*
* @returns {`${string}?${string}`}
*/
const buildNestedUrl = (baseUrl, route, id, nested, searchParams = {}) => {
const buildNestedUrl = (baseUrl, route, id, nested, projectIds = [], searchParams = {}) => {
const url = `${baseUrl}/core_data/public/v1/${route}/${id}/${nested}`;
const params = new URLSearchParams(searchParams);

_.each(projectIds, (projectId) => {
params.append('project_ids[]', projectId);
});

return `${url}?${params}`;
};

Expand All @@ -24,14 +31,19 @@ const buildNestedUrl = (baseUrl, route, id, nested, searchParams = {}) => {
* @param baseUrl
* @param route
* @param id
* @param projectIds
* @param searchParams
*
* @returns {`${string}?${string}`}
*/
const buildUrl = (baseUrl, route, id, searchParams = {}) => {
const buildUrl = (baseUrl, route, id, projectIds = [], searchParams = {}) => {
const url = `${baseUrl}/core_data/public/v1/${route}/${id}`;
const params = new URLSearchParams(searchParams);

_.each(projectIds, (projectId) => {
params.append('project_ids[]', projectId);
});

return `${url}?${params}`;
};

Expand Down

0 comments on commit 8362f3e

Please sign in to comment.