Skip to content

Commit

Permalink
Merge pull request #26 from Wilcolab/copilot
Browse files Browse the repository at this point in the history
feat: Add GET and DELETE endpoints for comments
  • Loading branch information
OnFreund authored Jun 17, 2024
2 parents 8584f29 + 576e2db commit 9b8248b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,38 @@ const router = require("express").Router();
const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

/**
* Express router for handling comments API requests.
* @module routes/api/comments
*/

module.exports = router;

/**
* Route for getting all comments.
* @name GET /api/comments
* @function
* @async
* @param {Object} req - Express request object
* @param {Object} res - Express response object
* @returns {Object} - JSON response containing all comments
*/
router.get("/", async (req, res) => {
const comments = await Comment.find();
res.json(comments);
});

/**
* Route for deleting a comment by ID.
* @name DELETE /api/comments/:id
* @function
* @async
* @param {Object} req - Express request object
* @param {Object} res - Express response object
* @returns {Object} - JSON response indicating success
*/
router.delete("/:id", async (req, res) => {
const comment = await Comment.findById(req.params.id);
await comment.remove();
res.json({ success: true });
});

0 comments on commit 9b8248b

Please sign in to comment.