diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/respository/MovieInPlaylistRepository.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/respository/MovieInPlaylistRepository.java index 77e8e36..5aad3cf 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/respository/MovieInPlaylistRepository.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/respository/MovieInPlaylistRepository.java @@ -17,4 +17,6 @@ public interface MovieInPlaylistRepository extends JpaRepository findTop1ByPlaylistIdOrderByCreatedAtDesc(Long playlistId); + + int countByPlaylistId(Long playlistId); } diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/service/MovieInPlaylistQueryService.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/service/MovieInPlaylistQueryService.java index ce2aadf..33f667a 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/service/MovieInPlaylistQueryService.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/service/MovieInPlaylistQueryService.java @@ -31,4 +31,8 @@ public boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId) { public Optional findTop1ByPlaylistIdOrderByCreatedAtDesc(Long playlistId) { return movieInPlaylistRepository.findTop1ByPlaylistIdOrderByCreatedAtDesc(playlistId); } + + public int countByPlaylistId(Long playlistId) { + return movieInPlaylistRepository.countByPlaylistId(playlistId); + } } diff --git a/src/main/java/com/mookive/mookive_backend/playlist/application/dto/response/PlaylistResponse.java b/src/main/java/com/mookive/mookive_backend/playlist/application/dto/response/PlaylistResponse.java index 8e22e36..111f922 100644 --- a/src/main/java/com/mookive/mookive_backend/playlist/application/dto/response/PlaylistResponse.java +++ b/src/main/java/com/mookive/mookive_backend/playlist/application/dto/response/PlaylistResponse.java @@ -12,12 +12,16 @@ public static class PlaylistGetResponse { private Long playlistId; private String poster; private String name; + private String title; + private int total; @Builder - public PlaylistGetResponse(Long playlistId, String poster, String name) { + public PlaylistGetResponse(Long playlistId, String poster, String name, String title, int total) { this.playlistId = playlistId; this.poster = poster; this.name = name; + this.title = title; + this.total = total; } } } diff --git a/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java b/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java index 1a0968b..92bb594 100644 --- a/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java +++ b/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java @@ -14,11 +14,13 @@ public static Playlist mapToPlaylist(User user, PlaylistRequest.PlaylistCreateRe .build(); } - public static PlaylistResponse.PlaylistGetResponse mapToPlaylistGetResponse(Playlist playlist, String poster) { + public static PlaylistResponse.PlaylistGetResponse mapToPlaylistGetResponse(Playlist playlist, String poster, String title, int total) { return PlaylistResponse.PlaylistGetResponse.builder() .playlistId(playlist.getId()) .name(playlist.getName()) .poster(poster) + .title(title) + .total(total) .build(); } } diff --git a/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistGetService.java b/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistGetService.java index b443c4f..0dff650 100644 --- a/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistGetService.java +++ b/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistGetService.java @@ -1,5 +1,6 @@ package com.mookive.mookive_backend.playlist.application.service; +import com.mookive.mookive_backend.movie.domain.entity.Movie; import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; import com.mookive.mookive_backend.movieInPlaylist.domain.service.MovieInPlaylistQueryService; import com.mookive.mookive_backend.playlist.application.dto.response.PlaylistResponse; @@ -27,11 +28,16 @@ public List getPlaylist(Long userId) { List playlistGetRequestList = new ArrayList<>(); for (Playlist playlist : playlists) { String poster = null; + String title = null; Long playlistId = playlist.getId(); - Optional optionalMovieInPlaylist = movieInPlaylistQueryService.findTop1ByPlaylistIdOrderByCreatedAtDesc(playlistId); - if(optionalMovieInPlaylist.isPresent()) - poster = optionalMovieInPlaylist.get().getMovie().getPoster(); - PlaylistResponse.PlaylistGetResponse playlistGetResponse = PlaylistMapper.mapToPlaylistGetResponse(playlist, poster); + Optional movieInPlaylist = movieInPlaylistQueryService.findTop1ByPlaylistIdOrderByCreatedAtDesc(playlistId); + if(movieInPlaylist.isPresent()) { + Movie movie = movieInPlaylist.get().getMovie(); + poster = movie.getPoster(); + title = movie.getTitle(); + } + int total = movieInPlaylistQueryService.countByPlaylistId(playlistId) - 1; + PlaylistResponse.PlaylistGetResponse playlistGetResponse = PlaylistMapper.mapToPlaylistGetResponse(playlist, poster, title, total); playlistGetRequestList.add(playlistGetResponse); } return playlistGetRequestList;