Class CommentServiceImpl
java.lang.Object
com.example.blogs.app.api.comment.service.CommentServiceImpl
- All Implemented Interfaces:
CommentService
Orchestrates comment retrieval operations by coordinating with the comment repository adapter.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateComment(Long postId, Long userId, CommentWriteRequestDTO requestDTO) Creates a new comment on a specific post.voiddeleteCommentById(Long commentId) Deletes a comment by its ID.getCommentsByPostId(Long postId) Retrieves all comments associated with a specific post.updateCommentById(Long commentId, CommentWriteRequestDTO requestDTO) Updates a comment by its ID with new content.
-
Constructor Details
-
CommentServiceImpl
public CommentServiceImpl()
-
-
Method Details
-
getCommentsByPostId
Retrieves all comments associated with a specific post. Delegates to the repository adapter for data retrieval.- Specified by:
getCommentsByPostIdin interfaceCommentService- Parameters:
postId- the ID of the post- Returns:
- list of comments for the post
-
createComment
Creates a new comment on a specific post. Constructs the comment entity, persists it via the repository adapter, and converts to DTO.- Specified by:
createCommentin interfaceCommentService- Parameters:
postId- the ID of the post to comment onuserId- the ID of the user creating the commentrequestDTO- request containing the comment content- Returns:
- newly created comment as DTO
-
deleteCommentById
Deletes a comment by its ID. Delegates to the repository adapter for deletion and logs the operation.- Specified by:
deleteCommentByIdin interfaceCommentService- Parameters:
commentId- the ID of the comment to delete
-
updateCommentById
Updates a comment by its ID with new content. Retrieves the comment, updates its content, marks it as edited, and persists the changes.- Specified by:
updateCommentByIdin interfaceCommentService- Parameters:
commentId- the ID of the comment to updaterequestDTO- request containing the updated comment content- Returns:
- updated comment as DTO
- Throws:
FailedToUpdateCommentException- if the update operation fails
-