Class CommentRepositoryAdapterImpl

java.lang.Object
com.example.blogs.app.api.comment.repository.adapter.CommentRepositoryAdapterImpl
All Implemented Interfaces:
CommentRepositoryAdapter

@Component public class CommentRepositoryAdapterImpl extends Object implements CommentRepositoryAdapter
Wraps comment repository operations with exception translation for consistent error handling.
  • Constructor Details

    • CommentRepositoryAdapterImpl

      public CommentRepositoryAdapterImpl()
  • Method Details

    • findAllByPostId

      public List<CommentEntity> findAllByPostId(Long postId)
      Retrieves all comments associated with a specific post with exception translation. Wraps repository exceptions in a domain-specific exception for consistent error handling.
      Specified by:
      findAllByPostId in interface CommentRepositoryAdapter
      Parameters:
      postId - the ID of the post
      Returns:
      list of comments for the post
      Throws:
      FailedToFindCommentsByPostIdException - if the repository operation fails
    • save

      public CommentEntity save(CommentEntity commentEntity)
      Saves a comment entity to the database with exception translation. Wraps repository exceptions in a domain-specific exception for consistent error handling.
      Specified by:
      save in interface CommentRepositoryAdapter
      Parameters:
      commentEntity - the comment entity to save
      Returns:
      the saved comment entity with generated ID
      Throws:
      FailedToCreateCommentException - if the save operation fails
    • existsById

      public boolean existsById(Long commentId)
      Checks if a comment exists with the specified ID. Wraps repository exceptions in a domain-specific exception for consistent error handling.
      Specified by:
      existsById in interface CommentRepositoryAdapter
      Parameters:
      commentId - the ID of the comment
      Returns:
      true if a comment with the given ID exists, false otherwise
      Throws:
      FailedToCheckCommentExistenceException - if the check operation fails
    • existsByIdAndAuthorId

      public boolean existsByIdAndAuthorId(Long commentId, Long authorId)
      Checks if a comment exists with the specified ID and author ID. Wraps repository exceptions in a domain-specific exception for consistent error handling.
      Specified by:
      existsByIdAndAuthorId in interface CommentRepositoryAdapter
      Parameters:
      commentId - the ID of the comment
      authorId - the ID of the author
      Returns:
      true if a comment with the given ID and author exists, false otherwise
      Throws:
      FailedToCheckCommentExistenceException - if the check operation fails
    • deleteById

      public void deleteById(Long commentId)
      Deletes a comment by its ID with exception translation. Wraps repository exceptions in a domain-specific exception for consistent error handling.
      Specified by:
      deleteById in interface CommentRepositoryAdapter
      Parameters:
      commentId - the ID of the comment to delete
      Throws:
      FailedToDeleteCommentException - if the delete operation fails
    • findById

      public CommentEntity findById(Long commentId)
      Retrieves a comment by its ID with exception translation. Wraps repository exceptions in domain-specific exceptions for consistent error handling.
      Specified by:
      findById in interface CommentRepositoryAdapter
      Parameters:
      commentId - the ID of the comment to retrieve
      Returns:
      the comment entity if found
      Throws:
      CommentNotFoundException - if the comment does not exist
      FailedToFindCommentByIdException - if the retrieval operation fails