diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java index 93184fe..1a22935 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java @@ -42,6 +42,23 @@ public List getMovieInPl }).collect(Collectors.toList()); return movieInPlaylistDefaultResponseList; + } + + public List getMovieInPlayListLatest(Long playlistId) { + Playlist playlist = playlistQueryService.findById(playlistId); + Long userId = playlist.getUser().getId(); + List movieInPlaylistList = movieInPlaylistQueryService.findByPlaylistIdOrderByCreatedAtDesc(playlistId); + List movieInPlaylistDefaultResponseList = movieInPlaylistList.stream().map(movieInPlaylist -> + { + Long movieId = movieInPlaylist.getMovie().getId(); + Optional record = recordQueryService.findByUserIdAndMovieId(userId, movieId); + String rating = null; + if (record.isPresent()) { + rating = record.get().getRating(); + } + return MovieInPlaylistMapper.mapToMovieInPlaylistDefaultResponse(movieInPlaylist, rating); + }).collect(Collectors.toList()); + return movieInPlaylistDefaultResponseList; } } 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 0f1d092..77e8e36 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 @@ -10,6 +10,8 @@ public interface MovieInPlaylistRepository extends JpaRepository findByPlaylistId(Long playlistId); + List findByPlaylistIdOrderByCreatedAtDesc(Long playlistId); + void deleteByPlaylistIdAndMovieId(Long playlistId, Long movieId); boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId); 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 e513539..ce2aadf 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 @@ -20,6 +20,10 @@ public List findByPlaylistId(Long playlistId) { return movieInPlaylistRepository.findByPlaylistId(playlistId); } + public List findByPlaylistIdOrderByCreatedAtDesc(Long playlistId) { + return movieInPlaylistRepository.findByPlaylistIdOrderByCreatedAtDesc(playlistId); + } + public boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId) { return movieInPlaylistRepository.existsByPlaylistIdAndMovieId(playlistId, movieId); } diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/presentation/MovieInPlayListController.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/presentation/MovieInPlayListController.java index 0e0d938..7390fff 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/presentation/MovieInPlayListController.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/presentation/MovieInPlayListController.java @@ -26,11 +26,16 @@ public void createMovieInPlaylist(@RequestBody MovieInPlaylistRequest.MovieInPla movieInPlaylistCreateService.createMovieInPlaylist(movieInPlaylistCreateRequest); } - @GetMapping("/movieInPlaylist/{playlistId}") + @GetMapping("/movieInPlaylist/earliest/{playlistId}") public List getMovieInPlaylist(@PathVariable Long playlistId) { return movieInPlayListGetService.getMovieInPlayList(playlistId); } + @GetMapping("/movieInPlaylist/latest/{playlistId}") + public List getMovieInPlaylistLatest(@PathVariable Long playlistId) { + return movieInPlayListGetService.getMovieInPlayListLatest(playlistId); + } + @DeleteMapping("/movieInPlaylist/delete") public void deleteMovieInPlaylist(@RequestBody MovieInPlaylistRequest.MovieInPlaylistDeleteRequest movieInPlaylistDeleteRequest) { movieInPlaylistDeleteService.deleteMovieInPlayList(movieInPlaylistDeleteRequest);