diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java index c154ad24..1b6c09cc 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/CategoryShortFormPage.java @@ -7,16 +7,19 @@ public record CategoryShortFormPage( List shortForms, - boolean hasNext + boolean hasNext, + Integer nextPage ) { public static CategoryShortFormPage of(final List petVideos, - final boolean hasNext) { + final boolean hasNext, + final Integer nextPage) { return new CategoryShortFormPage( petVideos.stream() .map(ShortFormDto::of) .toList(), - hasNext + hasNext, + nextPage ); } } diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java index 2789070c..9587d79b 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/dto/response/HomeShortFormPage.java @@ -6,16 +6,19 @@ public record HomeShortFormPage( List shortForms, - boolean hasNext + boolean hasNext, + Integer nextPage ) { public static HomeShortFormPage of(final List petVideos, - final boolean hasNext) { + final boolean hasNext, + final Integer nextPage) { return new HomeShortFormPage( petVideos.stream() .map(ShortFormDto::of) .toList(), - hasNext + hasNext, + nextPage ); } } diff --git a/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java b/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java index 86663996..147a52cd 100644 --- a/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java +++ b/animory/src/main/java/com/daggle/animory/domain/shortform/service/ShortFormService.java @@ -28,26 +28,28 @@ public class ShortFormService { public HomeShortFormPage getHomeShortFormPage(final Pageable pageable) { // Fetch Join + Pageable 동시에 수행하는 경우 발생하는 문제(HHH000104) 해결을 위해 쿼리를 두 개로 분할하였습니다. - Slice petVideoIdSlice = petVideoJpaRepository.findPetVideoIdsBy(pageable); - List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIdSlice.getContent()); + final Slice petVideoIdSlice = petVideoJpaRepository.findPetVideoIdsBy(pageable); + final List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIdSlice.getContent()); // LikeCount DESC 순서로 조회하고, 반환된 페이지(Slice)를 랜덤으로 섞는다. return HomeShortFormPage.of( shuffleVideos(petVideos), - petVideoIdSlice.hasNext() + petVideoIdSlice.hasNext(), + getNextPage(petVideoIdSlice.hasNext(), pageable) ); } public CategoryShortFormPage getCategoryShortFormPage(final ShortFormSearchCondition searchCondition, final Pageable pageable) { - Slice petVideoIds = petVideoJpqlRepository + final Slice petVideoIds = petVideoJpqlRepository .findPetVideoIdsBy(searchCondition.type(), searchCondition.area(), pageable); - List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIds.getContent()); + final List petVideos = petVideoJpqlRepository.findAllByIds(petVideoIds.getContent()); return CategoryShortFormPage.of( shuffleVideos(petVideos), - petVideoIds.hasNext() + petVideoIds.hasNext(), + getNextPage(petVideoIds.hasNext(), pageable) ); } @@ -56,4 +58,9 @@ private List shuffleVideos(final List petVideos) { Collections.shuffle(petVideos); return petVideos; } + + private Integer getNextPage(final boolean hasNext, + final Pageable pageable) { + return hasNext ? pageable.getPageNumber() + 1 : null; + } }