-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from CodeForAfrica/chore/charterafrica_api_re…
…sources @/charterafrica Move all documents API queries to /resources
- Loading branch information
Showing
7 changed files
with
79 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 17 additions & 28 deletions
45
apps/charterafrica/src/pages/api/v1/opportunities/consultation/[media].page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,28 @@ | ||
import { fetchDocuments } from "@/charterafrica/lib/sourceAfrica"; | ||
import { fetchResource } from "@/charterafrica/lib/youtube"; | ||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
const documents = async (req, res) => { | ||
const { q, media, pathname, ...rest } = req.query; | ||
import { fetchResource } from "@/charterafrica/lib/youtube"; | ||
|
||
try { | ||
const data = await fetchDocuments(q, pathname, rest); | ||
return res.status(200).json(data); | ||
} catch (error) { | ||
return res.status(500).json({ error }); | ||
} | ||
}; | ||
async function multimedia(req, res) { | ||
const { pathname, ...rest } = req.query; | ||
|
||
const multimedia = async (req, res) => { | ||
try { | ||
const { pathname, ...rest } = req.query; | ||
const data = await fetchResource(pathname, rest); | ||
return res.status(200).json(data); | ||
} catch (error) { | ||
return res.status(500).json(error); | ||
} | ||
}; | ||
const data = await fetchResource(pathname, rest); | ||
return res.status(200).json(data); | ||
} | ||
|
||
const mediaMap = { | ||
documents, | ||
const fetchMediaMap = { | ||
multimedia, | ||
}; | ||
|
||
export default async function handler(req, res) { | ||
const { | ||
query: { media }, | ||
} = req; | ||
const response = mediaMap[media]; | ||
if (response) { | ||
return response(req, res); | ||
const { media } = req.query; | ||
const fetchMedia = fetchMediaMap[media]; | ||
if (fetchMedia) { | ||
try { | ||
return fetchMedia(req, res); | ||
} catch (err) { | ||
Sentry.captureException(err); | ||
return res.status(500).json(err); | ||
} | ||
} | ||
return res.status(404).json({ message: "UNKNOWN_MEDIA", media }); | ||
} |
54 changes: 54 additions & 0 deletions
54
apps/charterafrica/src/pages/api/v1/resources/[type].page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
import fetchDatasets from "@/charterafrica/lib/openAfrica"; | ||
import { fetchDocuments } from "@/charterafrica/lib/sourceAfrica"; | ||
|
||
async function datasets(req, res) { | ||
const { | ||
sort = "metadata_created desc", | ||
tags, | ||
countries, | ||
q = "", | ||
page = 1, | ||
pathname, | ||
locale, | ||
organizationId, | ||
} = req.query; | ||
|
||
const data = await fetchDatasets(organizationId, pathname, { | ||
q, | ||
page, | ||
sort, | ||
tags: tags?.split(","), | ||
countries: countries?.split(","), | ||
locale, | ||
}); | ||
return res.status(200).json(data); | ||
} | ||
|
||
async function documents(req, res) { | ||
const { q, pathname, ...rest } = req.query; | ||
|
||
const data = await fetchDocuments(q, pathname, rest); | ||
return res.status(200).json(data); | ||
} | ||
|
||
const fetchResourcesByType = { | ||
datasets, | ||
documents, | ||
}; | ||
|
||
export default async function handler(req, res) { | ||
const { type } = req.query; | ||
|
||
const fetchResources = fetchResourcesByType[type]; | ||
if (fetchResources) { | ||
try { | ||
return fetchResources(req, res); | ||
} catch (err) { | ||
Sentry.captureException(err); | ||
return res.status(500).json(err); | ||
} | ||
} | ||
return res.status(404).json({ message: "UNKNOWN_TYPE", type }); | ||
} |
39 changes: 0 additions & 39 deletions
39
apps/charterafrica/src/pages/api/v1/resources/datasets.page.js
This file was deleted.
Oops, something went wrong.
a59930f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
codeforafrica – ./
codeforafrica-git-main-codeforafrica.vercel.app
codeforafrica-codeforafrica.vercel.app
codeforafrica.vercel.app