Class CommentController
java.lang.Object
com.example.blogs.app.api.comment.controller.CommentController
Handles HTTP requests for comment-related operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateComment(UserPrincipal userPrincipal, Long postId, @NotNull @Valid CommentWriteRequestDTO requestDTO) Creates a new comment on a specific post.deleteCommentById(Long commentId) Deletes a comment by its ID.updateCommentById(Long commentId, @NotNull @Valid CommentWriteRequestDTO requestDTO) Updates a comment by its ID.
-
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 commentpostId- the ID of the post to comment onrequestDTO- 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 updaterequestDTO- request containing the updated comment content- Returns:
- updated comment with HTTP 200 status
-