diff --git a/src/main/java/cc/ryanc/halo/repository/PostRepository.java b/src/main/java/cc/ryanc/halo/repository/PostRepository.java index c1488651e..00cf013eb 100644 --- a/src/main/java/cc/ryanc/halo/repository/PostRepository.java +++ b/src/main/java/cc/ryanc/halo/repository/PostRepository.java @@ -6,10 +6,10 @@ import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.repository.base.BaseRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.lang.NonNull; import java.util.Date; import java.util.List; @@ -216,4 +216,14 @@ public interface PostRepository extends BaseRepository, JpaSpecifica */ @Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit", nativeQuery = true) List getPostsByLimit(@Param(value = "limit") int limit); + + /** + * Finds all posts by post type. + * + * @param postType post type must not be blank + * @param pageable page info must not be null + * @return a page of posts + */ + @NonNull + Page findAllByPostType(@NonNull String postType, @NonNull Pageable pageable); } diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java index e82ff8eb5..d32f44654 100755 --- a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java @@ -242,7 +242,7 @@ public class PostServiceImpl extends AbstractCrudService implements public List findPostLatest() { Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "postDate")); - Page postPage = postRepository.findAll(pageable); + Page postPage = postRepository.findAllByPostType("post", pageable); return postPage.getContent(); }