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 Jul 18, 2022
1 parent d521043 commit 5dbab20
Show file tree
Hide file tree
Showing 2 changed files with 38 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
36 changes: 36 additions & 0 deletions src/endpoints/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ const getGroupOverview = contentTypesProvided([
]);


/* PUT
*/
const putGroupOverviewMarkdown = contentTypesProvided([
["text/markdown", receiveGroupOverview(req => req.context.source)],
]);


const putGroupOverview = contentTypesProvided([
["text/markdown", putGroupOverviewMarkdown],
]);


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


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

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

const urlCallback = async (method, headers) => await groupSource.urlFor("group-overview.md", method, headers);

return await receiveAny(req, res,
urlCallback,
"text/markdown" // TODO: put this in a class?
);
};
}


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

getGroupOverview,
putGroupOverview,
};

0 comments on commit 5dbab20

Please sign in to comment.