Skip to content

Commit

Permalink
Merge pull request #18 from Wilcolab/copilot
Browse files Browse the repository at this point in the history
Add GET and DELETE routes for comments
  • Loading branch information
OnFreund authored Apr 8, 2024
2 parents 213f08a + 286981f commit 480d9b8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,33 @@ const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

module.exports = router;

router.get("/", (req, res) => {
Comment.find()
.then((comments) => {
res.json(comments);
})
.catch((err) => {
console.log(err);
});
}
);

// Implement a delete endpoint for comments
router.delete("/:id", async (req, res) => {
try {
/**
* Represents a comment object.
* @typedef {Object} Comment
* @property {string} id - The unique identifier of the comment.
* @property {string} content - The content of the comment.
* @property {string} author - The author of the comment.
* @property {Date} createdAt - The date and time when the comment was created.
* @property {Date} updatedAt - The date and time when the comment was last updated.
*/
const comment = await Comment.findByIdAndRemove(req.params.id);
res.json(comment);
} catch (err) {
console.log(err);
}
});

0 comments on commit 480d9b8

Please sign in to comment.