feat: implement DELETE /comments/:id route to delete a comment by ID
Summary
This pull request implements the DELETE /comments/:id route that allows authenticated users to delete a specific comment by its ID. The route ensures that only the author of the comment or an admin can perform the deletion.
Changes Implemented
Added deleteCommentById method to commentController to handle deleting a comment.
Created a new route in commentRoutes.js for DELETE /comments/:id, protected by authenticateToken.
Added verification to ensure only the author of the comment or an admin can delete the comment.
Implemented error handling to return 404 Not Found if the comment is not found.
Verified functionality with Postman tests.
How to Test
Delete Comment as Author:
Send a DELETE request to http://localhost:5000/comments/:id with a valid comment ID where the author matches the authenticated user.
Ensure the comment is deleted successfully.
Delete Comment as Admin:
Send a DELETE request to http://localhost:5000/comments/:id with a valid comment ID using an admin token.
Ensure the comment is deleted successfully.
Unauthorized Deletion Attempt:
Send a DELETE request to http://localhost:5000/comments/:id with a valid comment ID using a token from a different user (not the author and not an admin).
Ensure the response is 403 Forbidden.
Comment Not Found:
Send a DELETE request to http://localhost:5000/comments/:id with a non-existent comment ID.
feat: implement DELETE /comments/:id route to delete a comment by ID
Summary
This pull request implements the
DELETE /comments/:id
route that allows authenticated users to delete a specific comment by its ID. The route ensures that only the author of the comment or an admin can perform the deletion.Changes Implemented
deleteCommentById
method tocommentController
to handle deleting a comment.commentRoutes.js
forDELETE /comments/:id
, protected byauthenticateToken
.404 Not Found
if the comment is not found.How to Test
Delete Comment as Author:
DELETE
request tohttp://localhost:5000/comments/:id
with a valid comment ID where the author matches the authenticated user.Delete Comment as Admin:
DELETE
request tohttp://localhost:5000/comments/:id
with a valid comment ID using an admin token.Unauthorized Deletion Attempt:
DELETE
request tohttp://localhost:5000/comments/:id
with a valid comment ID using a token from a different user (not the author and not an admin).403 Forbidden
.Comment Not Found:
DELETE
request tohttp://localhost:5000/comments/:id
with a non-existent comment ID.404 Not Found
.Example Request (Admin)
Example Response
New Issues Created
Resolves #152