Skip to content

Commit

Permalink
[wip] Implement GET /groups/:groupName/overview GET
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Jul 14, 2022
1 parent 547b03b commit 4f5452c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
getNarrative,
putNarrative,
deleteNarrative,
getGroupOverview,
} = endpoints.sources;

const {
Expand Down Expand Up @@ -303,6 +304,12 @@ app.routeAsync("/groups/:groupName/narratives/*")
.deleteAsync(deleteNarrative)
;

app.routeAsync("/groups/:groupName/overview")
.getAsync(getGroupOverview)
// .putAsync(putGroupOverview)
// .deleteAsync(deleteGroupOverview)
;

app.routeAsync("/groups/:groupName/*")
.all(setDataset(req => req.params[0]))
.getAsync(getDataset)
Expand Down
33 changes: 33 additions & 0 deletions src/endpoints/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ const getNarrative = contentTypesProvided([
]);


const getGroupOverviewMarkdown = contentTypesProvided([
["text/markdown", sendGroupOverview(req => req.context.source)],
]);


const getGroupOverview = contentTypesProvided([
["text/markdown", getGroupOverviewMarkdown],
]);


/* PUT
*/
const receiveNarrativeSubresource = type =>
Expand Down Expand Up @@ -292,6 +302,27 @@ function pathParts(path = "") {
}


/**
* Generate an Express endpoint that sends a group overview
* determined by the request.
*
* @param {sourceExtractor} sourceExtractor - Function to provide the Source instance from the request
* @returns {expressEndpointAsync}
*/
function sendGroupOverview(sourceExtractor) {
return async (req, res) => {
const groupSource = sourceExtractor(req);

authz.assertAuthorized(req.user, authz.actions.Read, groupSource);

return await sendAny(req, res,
await groupSource.urlFor("group-overview.md"),
"text/markdown" // TODO: put this in a class?
);
};
}


/**
* Generate an Express endpoint that sends a dataset or narrative Subresource
* determined by the request.
Expand Down Expand Up @@ -712,4 +743,6 @@ module.exports = {

sendDatasetSubresource,
sendNarrativeSubresource,

getGroupOverview,
};

0 comments on commit 4f5452c

Please sign in to comment.