Class PostRepositoryAdapterImpl

java.lang.Object
com.example.blogs.app.api.post.repository.adapter.PostRepositoryAdapterImpl
All Implemented Interfaces:
PostRepositoryAdapter

@Component public class PostRepositoryAdapterImpl extends Object implements PostRepositoryAdapter
Wraps post repository operations with exception translation for consistent error handling.
  • Constructor Details

    • PostRepositoryAdapterImpl

      public PostRepositoryAdapterImpl()
  • Method Details

    • findByAuthorId

      public List<PostEntity> findByAuthorId(long userId)
      Retrieves all posts authored by the specified user with exception translation. Wraps repository exceptions in a domain-specific exception for consistent error handling.
      Specified by:
      findByAuthorId in interface PostRepositoryAdapter
      Parameters:
      userId - the ID of the author
      Returns:
      list of posts by the author
      Throws:
      FailedToFindPostsByAuthorIdException - if the repository operation fails
    • deleteById

      public void deleteById(Long postId)
      Deletes a post by its ID with exception translation. Verifies deletion success and wraps repository exceptions in domain-specific exceptions.
      Specified by:
      deleteById in interface PostRepositoryAdapter
      Parameters:
      postId - the ID of the post to delete
      Throws:
      PostNotFoundException - if the post does not exist
      FailedToDeletePostException - if the repository operation fails
    • findBySlug

      public PostEntity findBySlug(String slug)
      Retrieves a post by its unique slug identifier with exception translation. Wraps repository exceptions in domain-specific exceptions for consistent error handling.
      Specified by:
      findBySlug in interface PostRepositoryAdapter
      Parameters:
      slug - the unique slug of the post
      Returns:
      the post entity
      Throws:
      PostNotFoundException - if the post does not exist
      FailedToFindPostBySlugException - if the repository operation fails
    • existsById

      public boolean existsById(long postId)
      Checks if a post exists by its ID.
      Specified by:
      existsById in interface PostRepositoryAdapter
      Parameters:
      postId - the ID of the post
      Returns:
      true if the post exists, false otherwise
    • existsByIdAndAuthorId

      public boolean existsByIdAndAuthorId(long postId, long authorId)
      Checks if a post exists by its ID and author ID.
      Specified by:
      existsByIdAndAuthorId in interface PostRepositoryAdapter
      Parameters:
      postId - the ID of the post
      authorId - the ID of the author
      Returns:
      true if the post exists and belongs to the author, false otherwise
    • findById

      public PostEntity findById(long postId)
      Retrieves a post by its ID with exception translation. Wraps repository exceptions in domain-specific exceptions for consistent error handling.
      Specified by:
      findById in interface PostRepositoryAdapter
      Parameters:
      postId - the ID of the post
      Returns:
      the post entity
      Throws:
      PostNotFoundException - if the post does not exist
      FailedToFindPostByIdException - if the repository operation fails
    • update

      public PostEntity update(PostEntity postEntity)
      Updates a post entity with exception translation. Wraps repository exceptions in domain-specific exceptions for consistent error handling.
      Specified by:
      update in interface PostRepositoryAdapter
      Parameters:
      postEntity - the post entity to update
      Returns:
      the updated post entity
      Throws:
      FailedToUpdatePostException - if the repository operation fails
    • save

      public PostEntity save(PostEntity postEntity)
      Saves a new post entity with exception translation. Wraps repository exceptions in domain-specific exceptions for consistent error handling.
      Specified by:
      save in interface PostRepositoryAdapter
      Parameters:
      postEntity - the post entity to save
      Returns:
      the saved post entity with generated ID
      Throws:
      FailedToSavePostException - if the repository operation fails