Interface PostRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<PostEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<PostEntity,Long>, org.springframework.data.repository.ListCrudRepository<PostEntity,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<PostEntity,Long>, org.springframework.data.repository.PagingAndSortingRepository<PostEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<PostEntity>, org.springframework.data.repository.Repository<PostEntity,Long>

public interface PostRepository extends org.springframework.data.jpa.repository.JpaRepository<PostEntity,Long>
JPA repository for managing post persistence operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    Deletes a post by its ID and returns the deleted post's ID.
    boolean
    existsById(long postId)
    Checks if a post exists by its ID.
    boolean
    existsByIdAndAuthorId(long postId, long authorId)
    Checks if a post exists by its ID and author ID.
    findByAuthorId(long userId)
    Retrieves all posts authored by the specified user.
    findById(long postId)
    Retrieves a post by its ID.
    Retrieves a post by its unique slug identifier.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByAuthorId

      List<PostEntity> findByAuthorId(long userId)
      Retrieves all posts authored by the specified user.
      Parameters:
      userId - the ID of the author
      Returns:
      list of posts by the author
    • deleteByIdReturningCount

      @Query(value="DELETE FROM posts WHERE id = :id RETURNING id", nativeQuery=true) Long deleteByIdReturningCount(@Param("id") Long postId)
      Deletes a post by its ID and returns the deleted post's ID.
      Parameters:
      postId - the ID of the post to delete
      Returns:
      the ID of the deleted post, or null if no post was found
    • findBySlug

      Optional<PostEntity> findBySlug(String slug)
      Retrieves a post by its unique slug identifier.
      Parameters:
      slug - the unique slug of the post
      Returns:
      optional containing the post if found, empty otherwise
    • existsById

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

      boolean existsByIdAndAuthorId(long postId, long authorId)
      Checks if a post exists by its ID and author ID.
      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

      Optional<PostEntity> findById(long postId)
      Retrieves a post by its ID.
      Parameters:
      postId - the ID of the post
      Returns:
      optional containing the post if found, empty otherwise