Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vps 25/resource api definitions are implemented #216

Merged
merged 18 commits into from
Aug 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
364bd3b
[VPS-25] feat: created resource page and implemented API for creating…
jacobmathew105 Aug 3, 2024
ad08938
[VPS-25] feat: implemented retrieving a specific/visible resource, de…
jacobmathew105 Aug 4, 2024
802e3b7
[VPS-25] feat: added in the authentication routing
jacobmathew105 Aug 4, 2024
e3cf6e0
feat: added flag endpoints to add and remove
codecreator127 Aug 4, 2024
481bc28
Merge branch 'master' into VPS-25/Resource-API-Definitions-are-implem…
codecreator127 Aug 4, 2024
d167368
feat: added DAOs for adding and removing flags
codecreator127 Aug 4, 2024
020e253
fix: added resources to router, added a frontend
codecreator127 Aug 5, 2024
c4a7c02
fix: fixed all the resourceDaos and tested them
codecreator127 Aug 6, 2024
0b5f8bb
chore: removed button on frontend for testing apis
codecreator127 Aug 8, 2024
1df8c93
feat: added the api to update a resource
jacobmathew105 Aug 10, 2024
bfac761
Merge branch 'VPS-25/Resource-API-Definitions-are-implemented' of htt…
codecreator127 Aug 10, 2024
6f0e45e
chore: removed duplicate resources api
codecreator127 Aug 10, 2024
ac49a79
feat: added dao for updating a resource
codecreator127 Aug 11, 2024
13e7d32
chore: ran prettier
codecreator127 Aug 12, 2024
f1166c9
chore: fixed linter issues
codecreator127 Aug 12, 2024
d7ca066
chore: removed unused import
codecreator127 Aug 13, 2024
b411752
fix: added error handling and changed forbidden to
codecreator127 Aug 15, 2024
dfae757
chore: added jsdocs to resources APIs
codecreator127 Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 62 additions & 7 deletions backend/src/routes/api/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ const HTTP_INTERNAL_SERVER_ERROR = 500;
// Apply auth middleware to all routes below this point
router.use(auth);

// Create a New Resource
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch on the 5xx

* @route POST /
* @desc Create a New Resource
* @param {Object} req.body - The resource details.
* @param {string} req.body.type - The type of the resource.
* @param {string} req.body.content - The content of the resource.
* @param {string} req.body.name - The name of the resource.
* @returns {Object} 201 - The newly created resource.
*/
router.post(
"/",
handle(async (req, res) => {
Expand All @@ -34,7 +42,14 @@ router.post(
})
);

// Retrieve a Specific Resource
/**
* @route GET /:resourceId
* @desc Retrieve a Specific Resource
* @param {string} req.params.resourceId - The unique identifier of the resource.
* @returns {Object} 200 - The resource details.
* @returns {string} 400 - Bad Request if resourceId is not provided.
* @returns {string} 404 - Not Found if the resource does not exist.
*/
router.get("/:resourceId", async (req, res) => {
if (!req.params.resourceId) {
return res.status(HTTP_BAD_REQUEST).send("Bad Request");
Expand All @@ -46,7 +61,14 @@ router.get("/:resourceId", async (req, res) => {
return res.status(HTTP_OK).json(resource);
});

// Delete a Resource
/**
* @route DELETE /:resourceId
* @desc Delete a Resource
* @param {string} req.params.resourceId - The unique identifier of the resource.
* @returns {string} 204 - Resource deleted successfully.
* @returns {string} 400 - Bad Request if resourceId is not provided.
* @returns {string} 404 - Not Found if the resource does not exist.
*/
router.delete("/:resourceId", async (req, res) => {
if (!req.params.resourceId) {
return res.status(HTTP_BAD_REQUEST).send("Bad Request");
Expand All @@ -58,7 +80,13 @@ router.delete("/:resourceId", async (req, res) => {
return res.status(HTTP_NO_CONTENT).send("Resource deleted");
});

// Retrieve All Visible Resources
/**
* @route GET /group/:groupId
* @desc Retrieve All Visible Resources for a Group
* @param {string} req.params.groupId - The unique identifier of the group.
* @returns {Object[]} 200 - An array of visible resources for the group.
* @returns {string} 400 - Bad Request if groupId is not provided.
*/
router.get("/group/:groupId", async (req, res) => {
const { groupId } = req.params;
if (!groupId) {
Expand All @@ -68,7 +96,14 @@ router.get("/group/:groupId", async (req, res) => {
return res.status(HTTP_OK).json(resources);
});

// Add a flag to group flags
/**
* @route POST /group/:groupId/:flag
* @desc Add a Flag to Group Flags
* @param {string} req.params.groupId - The unique identifier of the group.
* @param {string} req.params.flag - The flag to be added.
* @returns {string[]} 200 - The updated list of flags for the group.
* @returns {string} 400 - Bad Request if groupId or flag is not provided.
*/
router.post("/group/:groupId/:flag", async (req, res) => {
const { groupId, flag } = req.params;
if (!groupId || !flag) {
Expand All @@ -78,7 +113,14 @@ router.post("/group/:groupId/:flag", async (req, res) => {
return res.status(HTTP_OK).json(flags);
});

// Remove a flag from group flags
/**
* @route DELETE /group/:groupId/:flag
* @desc Remove a Flag from Group Flags
* @param {string} req.params.groupId - The unique identifier of the group.
* @param {string} req.params.flag - The flag to be removed.
* @returns {string[]} 200 - The updated list of flags for the group.
* @returns {string} 400 - Bad Request if groupId or flag is not provided.
*/
router.delete("/group/:groupId/:flag", async (req, res) => {
const { groupId, flag } = req.params;
if (!groupId || !flag) {
Expand All @@ -88,7 +130,20 @@ router.delete("/group/:groupId/:flag", async (req, res) => {
return res.status(HTTP_OK).json(flags);
});

// Update a Resource
/**
* @route PUT /:resourceId
* @desc Update a Resource
* @param {string} req.params.resourceId - The unique identifier of the resource.
* @param {Object} req.body - The updated resource details.
* @param {string} req.body.type - The type of the resource.
* @param {string} req.body.content - The content of the resource.
* @param {string} req.body.name - The name of the resource.
* @returns {Object} 200 - The updated resource.
* @returns {string} 400 - Bad Request if required fields are missing.
* @returns {string} 404 - Not Found if the resource does not exist.
* @returns {string} 500 - Internal Server Error if an unexpected error occurs.
*/

router.put("/:resourceId", async (req, res) => {
const { resourceId } = req.params;
const { name, type, content } = req.body;
Expand Down
Loading