Class CommentController

java.lang.Object
com.example.blogs.app.api.comment.controller.CommentController

@RestController public class CommentController extends Object
Handles HTTP requests for comment-related operations.
  • Constructor Details

    • CommentController

      public CommentController()
  • Method Details

    • createComment

      @PostMapping("/posts/{postId}/comment") public ResponseEntity<CommentDTO> createComment(@AuthenticationPrincipal UserPrincipal userPrincipal, @PathVariable Long postId, @NotNull @Valid @RequestBody @NotNull @Valid CommentWriteRequestDTO requestDTO)
      Creates a new comment on a specific post. Validates the request and delegates to the service layer for business logic.
      Parameters:
      userPrincipal - authenticated user making the comment
      postId - the ID of the post to comment on
      requestDTO - request containing the comment content
      Returns:
      newly created comment with HTTP 201 status
    • deleteCommentById

      @DeleteMapping("/comments/{commentId}") @PreAuthorize("@commentSecurity.isOwner(#commentId)") public ResponseEntity<Void> deleteCommentById(@PathVariable Long commentId)
      Deletes a comment by its ID. Requires the authenticated user to be the owner of the comment.
      Parameters:
      commentId - the ID of the comment to delete
      Returns:
      HTTP 204 No Content status upon successful deletion
    • updateCommentById

      @PatchMapping("/comments/{commentId}") @PreAuthorize("@commentSecurity.isOwner(#commentId)") public ResponseEntity<CommentDTO> updateCommentById(@PathVariable Long commentId, @NotNull @Valid @RequestBody @NotNull @Valid CommentWriteRequestDTO requestDTO)
      Updates a comment by its ID. Requires the authenticated user to be the owner of the comment.
      Parameters:
      commentId - the ID of the comment to update
      requestDTO - request containing the updated comment content
      Returns:
      updated comment with HTTP 200 status