Class CommentServiceImpl

java.lang.Object
com.example.blogs.app.api.comment.service.CommentServiceImpl
All Implemented Interfaces:
CommentService

@Service public class CommentServiceImpl extends Object implements CommentService
Orchestrates comment retrieval operations by coordinating with the comment repository adapter.
  • Constructor Details

    • CommentServiceImpl

      public CommentServiceImpl()
  • Method Details

    • getCommentsByPostId

      public List<CommentEntity> getCommentsByPostId(Long postId)
      Retrieves all comments associated with a specific post. Delegates to the repository adapter for data retrieval.
      Specified by:
      getCommentsByPostId in interface CommentService
      Parameters:
      postId - the ID of the post
      Returns:
      list of comments for the post
    • createComment

      public CommentDTO createComment(Long postId, Long userId, CommentWriteRequestDTO requestDTO)
      Creates a new comment on a specific post. Constructs the comment entity, persists it via the repository adapter, and converts to DTO.
      Specified by:
      createComment in interface CommentService
      Parameters:
      postId - the ID of the post to comment on
      userId - the ID of the user creating the comment
      requestDTO - request containing the comment content
      Returns:
      newly created comment as DTO
    • deleteCommentById

      public void deleteCommentById(Long commentId)
      Deletes a comment by its ID. Delegates to the repository adapter for deletion and logs the operation.
      Specified by:
      deleteCommentById in interface CommentService
      Parameters:
      commentId - the ID of the comment to delete
    • updateCommentById

      public CommentDTO updateCommentById(Long commentId, CommentWriteRequestDTO requestDTO)
      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:
      updateCommentById in interface CommentService
      Parameters:
      commentId - the ID of the comment to update
      requestDTO - request containing the updated comment content
      Returns:
      updated comment as DTO
      Throws:
      FailedToUpdateCommentException - if the update operation fails