Skip to content

Commit

Permalink
Merge pull request #15 from Wilcolab/copilot_quest
Browse files Browse the repository at this point in the history
Add comment-related API endpoints
  • Loading branch information
OnFreund authored Mar 18, 2024
2 parents c56f368 + 06fc8cb commit 89b7d50
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,48 @@ const router = require("express").Router();
const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

/**
* Express router for handling comment-related API endpoints.
* @module routes/api/comments
*/

module.exports = router;

/**
* GET /api/comments
* Retrieves all comments.
* @name GET/api/comments
* @function
* @memberof module:routes/api/comments
* @param {Object} req - Express request object.
* @param {Object} res - Express response object.
* @returns {Object} - JSON response containing the retrieved comments.
*/
router.get("/", (req, res) => {
Comment.find()
.then((comments) => {
res.json({ comments });
})
.catch((err) => {
console.log(err);
});
});

/**
* DELETE /api/comments/:id
* Deletes a comment by its ID.
* @name DELETE/api/comments/:id
* @function
* @memberof module:routes/api/comments
* @param {Object} req - Express request object.
* @param {Object} res - Express response object.
* @returns {Object} - JSON response indicating the success of the deletion.
*/
router.delete("/:id", async (req, res) => {
try {
await Comment.findByIdAndRemove(req.params.id);
res.json({ success: true });
} catch (err) {
console.log(err);
}
});

0 comments on commit 89b7d50

Please sign in to comment.