Skip to content

Commit

Permalink
fix: migrate from v1 to v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelstan committed Mar 18, 2023
1 parent 16b0ef2 commit a6962d5
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 170 deletions.
26 changes: 26 additions & 0 deletions src/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ import log from 'loglevel';
import apiPaths from 'models/apiPaths';
import { requestAPI } from './utils';

export async function getFeaturedGrowers() {
try {
const url = apiPaths.featuredGrowers;
const begin = Date.now();
const res = await axios.get(url);
const data = await res.data;
log.warn('url:', url, 'took:', Date.now() - begin);
return data.grower_accounts;
} catch (err) {
log.error(err.message);
throw err.message;
}
}
export async function getCaptures() {
try {
const url = apiPaths.getCaptures;
const begin = Date.now();
const res = await axios.get(url);
const data = await res.data;
log.warn('url:', url, 'took:', Date.now() - begin);
return data.captures;
} catch (err) {
log.error(err.message);
throw err.message;
}
}
export async function getFeaturedTrees() {
try {
const url = apiPaths.featuredTrees;
Expand Down
4 changes: 3 additions & 1 deletion src/models/apiPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { urlJoin } from 'url-join-ts';
const host = process.env.NEXT_PUBLIC_API || '';
const hostV2 = process.env.NEXT_PUBLIC_API_V2 || '';
const apiPaths = {
featuredTrees: urlJoin(host, '/trees/featured'),
featuredTrees: urlJoin(host, 'v2/trees/featured'),
featuredGrowers: urlJoin(host, 'v2/growers/featured'),
getCaptures: urlJoin(host, 'v2/captures'),
countriesLatLon: (lat = '', lon = '') =>
urlJoin(host, `/countries?lat=${lat}&lon=${lon}`),
leaders: urlJoin(host, '/countries/leaderboard'),
Expand Down
Loading

0 comments on commit a6962d5

Please sign in to comment.