Fix an implicit refactoring

pull/137/head
johnniang 2019-03-05 00:44:38 +08:00
parent 783162ffc9
commit 168a320edc
2 changed files with 12 additions and 2 deletions

View File

@ -6,10 +6,10 @@ import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.repository.base.BaseRepository; import cc.ryanc.halo.repository.base.BaseRepository;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; 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.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.lang.NonNull;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -216,4 +216,14 @@ public interface PostRepository extends BaseRepository<Post, Long>, JpaSpecifica
*/ */
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit", nativeQuery = true) @Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit", nativeQuery = true)
List<Post> getPostsByLimit(@Param(value = "limit") int limit); List<Post> 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<Post> findAllByPostType(@NonNull String postType, @NonNull Pageable pageable);
} }

View File

@ -242,7 +242,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Long> implements
public List<Post> findPostLatest() { public List<Post> findPostLatest() {
Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "postDate")); Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "postDate"));
Page<Post> postPage = postRepository.findAll(pageable); Page<Post> postPage = postRepository.findAllByPostType("post", pageable);
return postPage.getContent(); return postPage.getContent();
} }