Skip to content

Commit

Permalink
Merge pull request #19 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 9, 2024
2 parents 0eafedc + 87aefd9 commit 1aa4ccc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,31 @@ const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

module.exports = router;

router.get("/", async (req, res) => {
const comments = await Comment.find();
res.json(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.findById(req.params.id);
if (!comment) {
return res.status(404).json({ message: "Comment not found" });
}
await comment.remove();
res.json({ message: "Comment removed" });
} catch (error) {
res.status(500).json({ message: "Internal server error" });
}
});

0 comments on commit 1aa4ccc

Please sign in to comment.