Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/delete-comments-by-user-id #204

Merged
merged 1 commit into from
Jul 20, 2024

Conversation

benoit-bremaud
Copy link
Owner

feat: implement DELETE /comments/user/:userId route to delete all comments by user ID

Summary

This pull request implements the DELETE /comments/user/:userId route that allows authenticated users to delete all comments by a specific user ID. The route ensures that only the author of the comments or an admin can perform the deletion.

Changes Implemented

  • Added deleteCommentsByUserId method to commentController to handle deleting all comments by user ID.
  • Created a new route in commentRoutes.js for DELETE /comments/user/:userId, protected by authenticateToken.
  • Implemented error handling to return 404 Not Found if no comments are found for the user.
  • Verified functionality with Postman tests.

How to Test

  1. Delete All Comments as Author or Admin:

    • Send a DELETE request to http://localhost:5000/comments/user/:userId with a valid user ID and an admin token or a token belonging to the author in the Authorization header.
    • Ensure the response includes { message: 'All comments deleted successfully' }.
  2. Unauthorized Deletion Attempt:

    • Send a DELETE request to http://localhost:5000/comments/user/:userId with a valid user ID and a token from a different user (not the author and not an admin).
    • Ensure the response is 403 Forbidden.
  3. No Comments Found:

    • Send a DELETE request to http://localhost:5000/comments/user/:userId with a valid user ID but no comments for that user.
    • Ensure the response is 404 Not Found.

Example Request (Admin or Author)

DELETE /comments/user/669b2fba21af94e2afcdd828 HTTP/1.1
Host: localhost:5000
Authorization: Bearer <admin_or_author_token>

Example Response

{
    "message": "All comments deleted successfully"
}

New Issues Created

Resolves

Branch

feature/delete-comments-by-user-id

…ments by user ID

- Added deleteCommentsByUserId method to commentController to handle deleting all comments by user ID.
- Created a new route in commentRoutes.js for DELETE /comments/user/:userId, protected by authenticateToken and isAdmin.
- Implemented error handling to return 404 if no comments are found for the user.
- Verified functionality with Postman tests.

Resolves: #153
@benoit-bremaud benoit-bremaud added backend Label to indicate the backend team feature New functionality to be added api Related to API documentation and implementation labels Jul 20, 2024
@benoit-bremaud benoit-bremaud self-assigned this Jul 20, 2024
@benoit-bremaud benoit-bremaud linked an issue Jul 20, 2024 that may be closed by this pull request
6 tasks
Copy link
Owner Author

@benoit-bremaud benoit-bremaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job !

@benoit-bremaud benoit-bremaud merged commit 223d641 into main Jul 20, 2024
@benoit-bremaud benoit-bremaud deleted the feature/delete-comments-by-user-id branch July 25, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to API documentation and implementation backend Label to indicate the backend team feature New functionality to be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature/delete-comments-by-user-id
1 participant