mirror of https://github.com/halo-dev/halo
Abstract PostRepository for Post, Page and Journal entities
parent
8575bcb2ad
commit
a07bddcb7a
|
@ -1,7 +1,7 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.entity.Journal;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import cc.ryanc.halo.repository.base.BasePostRepository;
|
||||
|
||||
/**
|
||||
* Journal repository.
|
||||
|
@ -9,6 +9,6 @@ import cc.ryanc.halo.repository.base.BaseRepository;
|
|||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
public interface JournalRepository extends BaseRepository<Journal, Integer> {
|
||||
public interface JournalRepository extends BasePostRepository<Journal> {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.entity.Page;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import cc.ryanc.halo.repository.base.BasePostRepository;
|
||||
|
||||
/**
|
||||
* Page repository.
|
||||
|
@ -9,6 +9,6 @@ import cc.ryanc.halo.repository.base.BaseRepository;
|
|||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
public interface PageRepository extends BaseRepository<Page, Integer> {
|
||||
public interface PageRepository extends BasePostRepository<Page> {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.entity.Post;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import cc.ryanc.halo.repository.base.BasePostRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -17,48 +11,6 @@ import java.util.Optional;
|
|||
* @author johnniang
|
||||
* @author RYAN0UP
|
||||
*/
|
||||
public interface PostRepository extends BaseRepository<Post, Integer>, JpaSpecificationExecutor<Post> {
|
||||
public interface PostRepository extends BasePostRepository<Post>, JpaSpecificationExecutor<Post> {
|
||||
|
||||
/**
|
||||
* Finds posts by status and type.
|
||||
*
|
||||
* @param status status
|
||||
* @param pageable pageable
|
||||
* @return Page<Post>
|
||||
*/
|
||||
@NonNull
|
||||
Page<Post> findAllByStatus(@NonNull PostStatus status, @NonNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Counts posts by status and type.
|
||||
*
|
||||
* @param status status
|
||||
* @return posts count
|
||||
*/
|
||||
long countByStatus(@NonNull PostStatus status);
|
||||
|
||||
/**
|
||||
* Count by post url.
|
||||
*
|
||||
* @param url post url must not be blank
|
||||
* @return the count
|
||||
*/
|
||||
long countByUrl(@NonNull String url);
|
||||
|
||||
/**
|
||||
* Count by not url and post id not in.
|
||||
*
|
||||
* @param id post id must not be null
|
||||
* @param url post url must not be null
|
||||
* @return the count
|
||||
*/
|
||||
long countByIdNotAndUrl(@NonNull Integer id, @NonNull String url);
|
||||
|
||||
/**
|
||||
* Get post by url
|
||||
*
|
||||
* @param url post url
|
||||
* @return Optional<Post>
|
||||
*/
|
||||
Optional<Post> getByUrl(@NonNull String url);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package cc.ryanc.halo.repository.base;
|
||||
|
||||
import cc.ryanc.halo.model.entity.BasePost;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Base post repository.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface BasePostRepository<DOMAIN extends BasePost> extends BaseRepository<DOMAIN, Integer> {
|
||||
|
||||
/**
|
||||
* Finds posts by status and type.
|
||||
*
|
||||
* @param status status
|
||||
* @param pageable pageable
|
||||
* @return Page<Post>
|
||||
*/
|
||||
@NonNull
|
||||
Page<DOMAIN> findAllByStatus(@NonNull PostStatus status, @NonNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Counts posts by status and type.
|
||||
*
|
||||
* @param status status
|
||||
* @return posts count
|
||||
*/
|
||||
long countByStatus(@NonNull PostStatus status);
|
||||
|
||||
/**
|
||||
* Count by post url.
|
||||
*
|
||||
* @param url post url must not be blank
|
||||
* @return the count
|
||||
*/
|
||||
long countByUrl(@NonNull String url);
|
||||
|
||||
/**
|
||||
* Count by not url and post id not in.
|
||||
*
|
||||
* @param id post id must not be null
|
||||
* @param url post url must not be null
|
||||
* @return the count
|
||||
*/
|
||||
long countByIdNotAndUrl(@NonNull Integer id, @NonNull String url);
|
||||
|
||||
/**
|
||||
* Get post by url
|
||||
*
|
||||
* @param url post url
|
||||
* @return Optional<Post>
|
||||
*/
|
||||
Optional<DOMAIN> getByUrl(@NonNull String url);
|
||||
|
||||
}
|
Loading…
Reference in New Issue