Skip to content

Commit

Permalink
Merge pull request #697 from AlexsLemonade/arielsvn/v1-api-version
Browse files Browse the repository at this point in the history
Use versioned API endpoints
  • Loading branch information
arielsvn authored Jul 30, 2019
2 parents ae32ae0 + 657351d commit 527a0dd
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"formik": "^1.5.0",
"gsap": "^2.0.2",
"history": "^4.7.2",
"lodash": "^4.17.11",
"lodash": "^4.17.14",
"moment": "^2.24.0",
"nprogress": "^0.2.0",
"react": "^16.8.1",
Expand Down
2 changes: 1 addition & 1 deletion src/api/dashboad.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ajax } from '../common/helpers';

export async function fetchDashboardData(range = null) {
return range ? Ajax.get('/stats/', { range }) : Ajax.get('/stats');
return range ? Ajax.get('/v1/stats/', { range }) : Ajax.get('/v1/stats');
}
8 changes: 4 additions & 4 deletions src/api/dataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function getDataSet(dataSetId, tokenId = null) {
}
: {};

return Ajax.get(`/dataset/${dataSetId}/`, null, headers);
return Ajax.get(`/v1/dataset/${dataSetId}/`, null, headers);
}

export async function getDataSetDetails(dataSetId, tokenId = null) {
Expand All @@ -18,7 +18,7 @@ export async function getDataSetDetails(dataSetId, tokenId = null) {
: {};

const response = await Ajax.get(
`/dataset/${dataSetId}/`,
`/v1/dataset/${dataSetId}/`,
{ details: true },
headers
);
Expand All @@ -33,7 +33,7 @@ export async function getDataSetDetails(dataSetId, tokenId = null) {
* Creates a new dataset
*/
export async function createDataSet() {
return Ajax.post('/dataset/', { data: {} });
return Ajax.post('/v1/dataset/', { data: {} });
}

export async function updateDataSet(dataSetId, dataSet, details = false) {
Expand All @@ -45,7 +45,7 @@ export async function updateDataSet(dataSetId, dataSet, details = false) {
// When the api seels the `?details` parameter, it will include `experiments` and `organism_samples`
// in the response.
const result = await Ajax.put(
`/dataset/${dataSetId}/${details ? '?details=true' : ''}`,
`/v1/dataset/${dataSetId}/${details ? '?details=true' : ''}`,
{ data: dataSet }
);

Expand Down
2 changes: 1 addition & 1 deletion src/api/experiments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ajax } from '../common/helpers';

export async function getExperiment(accessionCode) {
return Ajax.get(`/experiments/${accessionCode}/`);
return Ajax.get(`/v1/experiments/${accessionCode}/`);
}
6 changes: 3 additions & 3 deletions src/api/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ajax } from '../common/helpers';
* @param {number} sampleId Id of the Sample
*/
export async function getDetailedSample(sampleId) {
return Ajax.get(`/samples/${sampleId}/`);
return Ajax.get(`/v1/samples/${sampleId}/`);
}

/**
Expand All @@ -16,7 +16,7 @@ export async function getDetailedSample(sampleId) {
* @param {number} limit
*/
export async function getAllDetailedSamples({ orderBy, filterBy, ...params }) {
const { count, results } = await Ajax.get('/samples/', {
const { count, results } = await Ajax.get('/v1/samples/', {
...params,
// send the accession codes as a string, otherwise they will be converted to an array parameter
ordering: orderBy,
Expand All @@ -27,7 +27,7 @@ export async function getAllDetailedSamples({ orderBy, filterBy, ...params }) {

export async function getGenomeBuild(organism) {
try {
const { assembly_name } = await Ajax.get('/transcriptome_indices/', {
const { assembly_name } = await Ajax.get('/v1/transcriptome_indices/', {
organism,
length: 'long',
});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SpeciesCompendia/DownloadCompendia.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default DownloadCompendia;

async function fetchCompendiaData() {
try {
const data = await Ajax.get('/compendia/');
const data = await Ajax.get('/v1/compendia/');
return uniq(data.map(x => x.organism_name));
} catch (e) {
return [];
Expand All @@ -95,7 +95,7 @@ async function fetchCompendiaData() {

async function downloadCompendia(organism, token) {
// refetch the compendia, now sending the token id to retrieve the download urls
const data = await Ajax.get('/compendia', null, { 'API-KEY': token });
const data = await Ajax.get('/v1/compendia', null, { 'API-KEY': token });

const computedFile = data
.filter(x => x.organism_name === organism)
Expand Down
6 changes: 3 additions & 3 deletions src/state/download/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const editDataSet = ({ dataSetId, ...params }) => async (
aggregate_by,
scale_by,
quantile_normalize,
} = await Ajax.put(`/dataset/${dataSetId}/`, {
} = await Ajax.put(`/v1/dataset/${dataSetId}/`, {
data: dataSet,
...params,
});
Expand Down Expand Up @@ -266,7 +266,7 @@ export const startDownload = ({

try {
await Ajax.put(
`/dataset/${dataSetId}/`,
`/v1/dataset/${dataSetId}/`,
{
start: true,
data: dataSet,
Expand Down Expand Up @@ -325,7 +325,7 @@ export const regenerateDataSet = dataSet => async dispatch => {
// 1. create a new dataset
const { id: dataSetId } = await createDataSet();
// 2. add the same data
await Ajax.put(`/dataset/${dataSetId}/`, {
await Ajax.put(`/v1/dataset/${dataSetId}/`, {
data,
aggregate_by,
scale_by,
Expand Down
4 changes: 2 additions & 2 deletions src/state/download/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('fetchDataSet', () => {

await store.dispatch(fetchDataSet());

expect(global.fetch.mock.calls[0][0]).toEqual(`/dataset/${DataSetId}/`);
expect(global.fetch.mock.calls[0][0]).toEqual(`/v1/dataset/${DataSetId}/`);
expect(store.getActions().map(x => x.type)).toEqual([
'DOWNLOAD_DATASET_FETCH',
'DOWNLOAD_DATASET_UPDATE',
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('fetchDataSet', () => {

await store.dispatch(fetchDataSet());

expect(global.fetch.mock.calls[0][0]).toEqual(`/dataset/${DataSetId}/`);
expect(global.fetch.mock.calls[0][0]).toEqual(`/v1/dataset/${DataSetId}/`);
expect(store.getActions().map(x => x.type)).toEqual([
'DOWNLOAD_DATASET_FETCH',
'DOWNLOAD_DROP',
Expand Down
6 changes: 3 additions & 3 deletions src/state/search/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function fetchResults({
}) {
return async (dispatch, getState) => {
try {
const apiResults = await Ajax.get('/search/', {
const apiResults = await Ajax.get('/v1/search/', {
...(query ? { search: query } : {}),
limit: size,
offset: (page - 1) * size,
Expand All @@ -83,7 +83,7 @@ export function fetchResults({
// each accession code requires an specific query to fetch the exact experiment
const promises = await Promise.all(
accessionCodes.map(code =>
Ajax.get('/search/', {
Ajax.get('/v1/search/', {
search: `accession_code:${code}`,
})
)
Expand Down Expand Up @@ -111,7 +111,7 @@ export function fetchResults({

if (!previousFilters) {
// make another request to the api to fetch the results
const { facets: previousFacets } = await Ajax.get('/search/', {
const { facets: previousFacets } = await Ajax.get('/v1/search/', {
...(query ? { search: query } : {}),
limit: 1,
...{
Expand Down
4 changes: 2 additions & 2 deletions src/state/search/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('fetching a dataset', () => {
const store = mockStore();
await store.dispatch(fetchResults({ query: 'cancer', ordering: '' }));
expect(global.fetch.mock.calls[0]).toEqual([
'/search/?search=cancer&limit=10&offset=0&ordering=_score',
'/v1/search/?search=cancer&limit=10&offset=0&ordering=_score',
]);
});

Expand All @@ -88,7 +88,7 @@ describe('fetching a dataset', () => {
fetchResults({ query: 'cancer', ordering: 'num_downloadable_samples' })
);
expect(global.fetch.mock.calls[0]).toEqual([
'/search/?search=cancer&limit=10&offset=0&ordering=num_downloadable_samples',
'/v1/search/?search=cancer&limit=10&offset=0&ordering=num_downloadable_samples',
]);
});
});
4 changes: 2 additions & 2 deletions src/state/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const loadToken = token => ({
});

export const createToken = () => async dispatch => {
const { id: tokenId } = await Ajax.post('/token/');
await Ajax.put(`/token/${tokenId}/`, { is_activated: true });
const { id: tokenId } = await Ajax.post('/v1/token/');
await Ajax.put(`/v1/token/${tokenId}/`, { is_activated: true });
dispatch(loadToken(tokenId));
return tokenId;
};
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6822,11 +6822,16 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.5, lodash@~4.17.10, lodash@~4.17.4:
"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.5, lodash@~4.17.10, lodash@~4.17.4:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

lodash@^4.17.11, lodash@^4.17.14:
version "4.17.14"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==

log-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
Expand Down

0 comments on commit 527a0dd

Please sign in to comment.