Fix issue#177

pull/205/head
johnniang 2019-06-03 13:47:25 +08:00
parent 4f15e8bf1e
commit 9b92867ea3
2 changed files with 21 additions and 3 deletions

View File

@ -429,6 +429,11 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
// Get all comments
Page<COMMENT> topCommentPage = baseCommentRepository.findAllByPostIdAndStatusAndParentId(targetId, status, 0L, pageable);
if (topCommentPage.isEmpty()) {
// If the comments is empty
return ServiceUtils.buildEmptyPageImpl(topCommentPage);
}
// Get top comment ids
Set<Long> topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId);

View File

@ -1,8 +1,6 @@
package run.halo.app.utils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.*;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@ -136,6 +134,21 @@ public class ServiceUtils {
return buildLatestPageable(top, "createTime");
}
/**
* Build empty page result.
*
* @param page page info must not be null
* @param <T> target page result type
* @param <S> source page result type
* @return empty page result
*/
@NonNull
public static <T, S> Page<T> buildEmptyPageImpl(@NonNull Page<S> page) {
Assert.notNull(page, "Page result must not be null");
return new PageImpl<>(Collections.emptyList(), page.getPageable(), page.getTotalElements());
}
/**
* Builds latest page request.
*