diff --git a/src/main/java/com/cabin/plat/domain/playlist/dto/PlaylistResponse.java b/src/main/java/com/cabin/plat/domain/playlist/dto/PlaylistResponse.java index 875db5d..3dbd359 100644 --- a/src/main/java/com/cabin/plat/domain/playlist/dto/PlaylistResponse.java +++ b/src/main/java/com/cabin/plat/domain/playlist/dto/PlaylistResponse.java @@ -5,7 +5,10 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Set; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; public class PlaylistResponse { @Getter @@ -23,6 +26,7 @@ public static class PlayListId { @NoArgsConstructor public static class Playlists { private List playlists; + private boolean hasNext; @Getter @Builder diff --git a/src/main/java/com/cabin/plat/domain/playlist/mapper/PlaylistMapper.java b/src/main/java/com/cabin/plat/domain/playlist/mapper/PlaylistMapper.java index e8b37d8..fbe7d6d 100644 --- a/src/main/java/com/cabin/plat/domain/playlist/mapper/PlaylistMapper.java +++ b/src/main/java/com/cabin/plat/domain/playlist/mapper/PlaylistMapper.java @@ -45,9 +45,10 @@ public PlaylistResponse.PlayListId toPlaylistId(Long playlistId) { .build(); } - public PlaylistResponse.Playlists toPlaylists(List playlistInfos) { + public PlaylistResponse.Playlists toPlaylists(List playlistInfos, boolean hasNext) { return PlaylistResponse.Playlists.builder() .playlists(playlistInfos) + .hasNext(hasNext) .build(); } diff --git a/src/main/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImpl.java b/src/main/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImpl.java index 0a1d207..872061f 100644 --- a/src/main/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImpl.java +++ b/src/main/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImpl.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -70,12 +71,12 @@ public PlaylistResponse.Playlists getPlaylists(Member member, int page, int size Pageable pageable = PageRequest.of(page, size, Sort.by(sorts)); // TODO: 효율 개선 - List playlists = playlistRepository.findAllByMember(member, pageable).getContent(); - List playlistInfos = playlists.stream().map(playlist -> { + Page playlists = playlistRepository.findAllByMember(member, pageable); + List playlistInfos = playlists.getContent().stream().map(playlist -> { List playlistTracks = findPlaylistTracksInPlaylist(playlist); return playlistMapper.toPlaylistInfo(playlist, playlistTracks); }).toList(); - return playlistMapper.toPlaylists(playlistInfos); + return playlistMapper.toPlaylists(playlistInfos, playlists.hasNext()); } @Override @@ -85,20 +86,20 @@ public PlaylistResponse.Playlists getSearchedPlaylists(Member member, String tit .toLowerCase(); if (refinedTitle.isEmpty() || refinedTitle.isBlank()) { - return playlistMapper.toPlaylists(Collections.emptyList()); + return playlistMapper.toPlaylists(Collections.emptyList(), false); } Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); - List playlists = playlistRepository. - findAllByMemberAndTitleContainingIgnoreCase(member, refinedTitle, pageable).getContent(); + Page playlists = playlistRepository. + findAllByMemberAndTitleContainingIgnoreCase(member, refinedTitle, pageable); // TODO: 효율 개선 - List playlistInfos = playlists.stream().map(playlist -> { + List playlistInfos = playlists.getContent().stream().map(playlist -> { List playlistTracks = findPlaylistTracksInPlaylist(playlist); return playlistMapper.toPlaylistInfo(playlist, playlistTracks); }).toList(); - return playlistMapper.toPlaylists(playlistInfos); + return playlistMapper.toPlaylists(playlistInfos, playlists.hasNext()); } @Transactional diff --git a/src/main/java/com/cabin/plat/domain/track/dto/TrackResponse.java b/src/main/java/com/cabin/plat/domain/track/dto/TrackResponse.java index 8ec64e4..2c8e54f 100644 --- a/src/main/java/com/cabin/plat/domain/track/dto/TrackResponse.java +++ b/src/main/java/com/cabin/plat/domain/track/dto/TrackResponse.java @@ -27,6 +27,7 @@ public static class TrackMapList { public static class TrackDetailList { @Schema(description = "트랙 디테일 리스트") private List trackDetails; + private boolean hasNext; } @Getter diff --git a/src/main/java/com/cabin/plat/domain/track/mapper/TrackMapper.java b/src/main/java/com/cabin/plat/domain/track/mapper/TrackMapper.java index 0f39ea5..02b6070 100644 --- a/src/main/java/com/cabin/plat/domain/track/mapper/TrackMapper.java +++ b/src/main/java/com/cabin/plat/domain/track/mapper/TrackMapper.java @@ -4,7 +4,10 @@ import com.cabin.plat.domain.track.dto.TrackRequest; import com.cabin.plat.domain.track.dto.TrackResponse; import com.cabin.plat.domain.track.dto.TrackResponse.TrackMap; -import com.cabin.plat.domain.track.entity.*; +import com.cabin.plat.domain.track.entity.Location; +import com.cabin.plat.domain.track.entity.Track; +import com.cabin.plat.domain.track.entity.TrackLike; +import com.cabin.plat.domain.track.entity.TrackReport; import java.time.LocalDateTime; import java.util.List; import org.springframework.stereotype.Component; @@ -71,9 +74,11 @@ public TrackResponse.MemberInfo toMemberInfo(Long memberId, String memberNicknam .build(); } - public TrackResponse.TrackDetailList toTrackDetailList(List trackDetails) { + public TrackResponse.TrackDetailList toTrackDetailList(List trackDetails, + boolean hasNext) { return TrackResponse.TrackDetailList.builder() .trackDetails(trackDetails) + .hasNext(hasNext) .build(); } diff --git a/src/main/java/com/cabin/plat/domain/track/service/TrackServiceImpl.java b/src/main/java/com/cabin/plat/domain/track/service/TrackServiceImpl.java index 9f16e17..c091eba 100644 --- a/src/main/java/com/cabin/plat/domain/track/service/TrackServiceImpl.java +++ b/src/main/java/com/cabin/plat/domain/track/service/TrackServiceImpl.java @@ -23,6 +23,7 @@ import java.util.Optional; import java.util.Random; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -170,14 +171,14 @@ public TrackResponse.TrackDetailList getTrackFeeds(Member member, int page, int sorts.add(Sort.Order.desc("createdAt")); Pageable pageable = PageRequest.of(page, size, Sort.by(sorts)); - List tracks = trackRepository.findAll(pageable).getContent(); + Page trackPage = trackRepository.findAll(pageable); - List trackDetails = tracks.stream() + List trackDetails = trackPage.getContent().stream() .filter(track -> track.getDeletedAt() == null) .map(track -> getTrackDetail(member, track)) .toList(); - return trackMapper.toTrackDetailList(trackDetails); + return trackMapper.toTrackDetailList(trackDetails, trackPage.hasNext()); } @Override diff --git a/src/test/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImplTest.java b/src/test/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImplTest.java index 31a0812..3a570a5 100644 --- a/src/test/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImplTest.java +++ b/src/test/java/com/cabin/plat/domain/playlist/service/PlaylistServiceImplTest.java @@ -353,9 +353,13 @@ class GetPlaylistsTests { // then assertThat(pagedPlaylists0.getPlaylists()).hasSize(1); + assertThat(pagedPlaylists0.isHasNext()).isTrue(); assertThat(pagedPlaylists1.getPlaylists()).hasSize(1); + assertThat(pagedPlaylists1.isHasNext()).isTrue(); assertThat(pagedPlaylists2.getPlaylists()).hasSize(1); + assertThat(pagedPlaylists2.isHasNext()).isFalse(); assertThat(pagedPlaylists3.getPlaylists()).hasSize(0); + assertThat(pagedPlaylists3.isHasNext()).isFalse(); } @Test diff --git a/src/test/java/com/cabin/plat/domain/track/service/TrackServiceTest.java b/src/test/java/com/cabin/plat/domain/track/service/TrackServiceTest.java index 51989ee..1bbdd58 100644 --- a/src/test/java/com/cabin/plat/domain/track/service/TrackServiceTest.java +++ b/src/test/java/com/cabin/plat/domain/track/service/TrackServiceTest.java @@ -12,6 +12,7 @@ import com.cabin.plat.domain.track.dto.TrackRequest; import com.cabin.plat.domain.track.dto.TrackResponse; import com.cabin.plat.domain.track.dto.TrackResponse.TrackDetail; +import com.cabin.plat.domain.track.dto.TrackResponse.TrackDetailList; import com.cabin.plat.domain.track.dto.TrackResponse.TrackMap; import com.cabin.plat.domain.track.entity.Location; import com.cabin.plat.domain.track.entity.Track; @@ -408,14 +409,17 @@ class getTrackFeedsTests { Member member = members.get(0); // when - List firstPageTracks = trackService.getTrackFeeds(member, 0, 4).getTrackDetails(); - List secondPageTracks = trackService.getTrackFeeds(member, 1, 4).getTrackDetails(); - List thirdPageTracks = trackService.getTrackFeeds(member, 2, 4).getTrackDetails(); + TrackDetailList firstPageTracks = trackService.getTrackFeeds(member, 0, 4); + TrackDetailList secondPageTracks = trackService.getTrackFeeds(member, 1, 4); + TrackDetailList thirdPageTracks = trackService.getTrackFeeds(member, 2, 4); // then - assertThat(firstPageTracks).hasSize(4); - assertThat(secondPageTracks).hasSize(2); - assertThat(thirdPageTracks).hasSize(0); + assertThat(firstPageTracks.getTrackDetails()).hasSize(4); + assertThat(firstPageTracks.isHasNext()).isTrue(); + assertThat(secondPageTracks.getTrackDetails()).hasSize(2); + assertThat(secondPageTracks.isHasNext()).isFalse(); + assertThat(thirdPageTracks.getTrackDetails()).hasSize(0); + assertThat(thirdPageTracks.isHasNext()).isFalse(); } @Test