Fix page top comments bug

pull/167/head^2
johnniang 2019-05-14 23:47:06 +08:00 committed by John Niang
parent 9578745677
commit 816af625e4
2 changed files with 14 additions and 2 deletions

View File

@ -84,7 +84,7 @@ public interface BaseCommentRepository<COMMENT extends BaseComment> extends Base
List<COMMENT> findAllByPostIdAndStatus(Integer postId, CommentStatus status); List<COMMENT> findAllByPostIdAndStatus(Integer postId, CommentStatus status);
/** /**
* Finds comments by post id, comment status. * Finds comments by post id and comment status.
* *
* @param postId post id must not be null * @param postId post id must not be null
* @param status comment status must not be null * @param status comment status must not be null
@ -94,6 +94,18 @@ public interface BaseCommentRepository<COMMENT extends BaseComment> extends Base
@NonNull @NonNull
Page<COMMENT> findAllByPostIdAndStatus(Integer postId, CommentStatus status, Pageable pageable); Page<COMMENT> findAllByPostIdAndStatus(Integer postId, CommentStatus status, Pageable pageable);
/**
* Finds comments by post id, comment status and parent id.
*
* @param postId post id must not be null
* @param status comment status must not be null
* @param parentId comment parent id must not be null
* @param pageable page info must not be null
* @return a page of comment
*/
@NonNull
Page<COMMENT> findAllByPostIdAndStatusAndParentId(Integer postId, CommentStatus status, Long parentId, Pageable pageable);
@Query("select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment.id), comment.parentId) " + @Query("select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment.id), comment.parentId) " +
"from BaseComment comment " + "from BaseComment comment " +
"where comment.parentId in ?1 " + "where comment.parentId in ?1 " +

View File

@ -425,7 +425,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
Assert.notNull(pageable, "Page info must not be null"); Assert.notNull(pageable, "Page info must not be null");
// Get all comments // Get all comments
Page<COMMENT> topCommentPage = baseCommentRepository.findAllByPostIdAndStatus(targetId, status, pageable); Page<COMMENT> topCommentPage = baseCommentRepository.findAllByPostIdAndStatusAndParentId(targetId, status, 0L, pageable);
// Get top comment ids // Get top comment ids
Set<Long> topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId); Set<Long> topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId);