Skip to content

Commit

Permalink
[wip] Implement PUT /groups/:groupName/overview
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Aug 23, 2022
1 parent d91affd commit 31f7f9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const {
putNarrative,
deleteNarrative,
getGroupOverview,
putGroupOverview,
} = endpoints.sources;

const {
Expand Down Expand Up @@ -306,7 +307,7 @@ app.routeAsync("/groups/:groupName/narratives/*")

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

Expand Down
27 changes: 27 additions & 0 deletions src/endpoints/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ const getGroupOverview = contentTypesProvided([
]);


/* PUT
*/
const putGroupOverview = contentTypesConsumed([
["text/markdown", receiveGroupOverview],
]);


/**
* Split a dataset or narrative `path` into an array of parts.
*
Expand Down Expand Up @@ -385,6 +392,25 @@ async function proxyFromUpstream(req, res, url, accept) {
}


/**
* An Express endpoint that receives a group overview determined by the request.
*
* @param {express.request} req - Express-style request instance
* @param {express.response} res - Express-style response instance
* @returns {expressEndpointAsync}
*/
async function receiveGroupOverview(req, res) {
const groupSource = req.context.source;

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

return await proxyToUpstream(req, res,
async (method, headers) => await groupSource.urlFor("group-overview.md", method, headers),
"text/markdown"
);
}


/**
* Generate an Express endpoint that receives a dataset or narrative
* Subresource determined by the request.
Expand Down Expand Up @@ -764,4 +790,5 @@ module.exports = {
sendNarrativeSubresource,

getGroupOverview,
putGroupOverview,
};

0 comments on commit 31f7f9f

Please sign in to comment.