Skip to content

Commit

Permalink
Merge pull request #43 from syyling/feat/38
Browse files Browse the repository at this point in the history
[feat] 플레이리스트 영화 최신순 조회 기능 추가
  • Loading branch information
syyling authored May 29, 2024
2 parents 68bab74 + 219aee4 commit fb596d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ public List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPl
}).collect(Collectors.toList());

return movieInPlaylistDefaultResponseList;
}

public List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPlayListLatest(Long playlistId) {
Playlist playlist = playlistQueryService.findById(playlistId);
Long userId = playlist.getUser().getId();

List<MovieInPlaylist> movieInPlaylistList = movieInPlaylistQueryService.findByPlaylistIdOrderByCreatedAtDesc(playlistId);
List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> movieInPlaylistDefaultResponseList = movieInPlaylistList.stream().map(movieInPlaylist ->
{
Long movieId = movieInPlaylist.getMovie().getId();
Optional<Record> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface MovieInPlaylistRepository extends JpaRepository<MovieInPlaylist

List<MovieInPlaylist> findByPlaylistId(Long playlistId);

List<MovieInPlaylist> findByPlaylistIdOrderByCreatedAtDesc(Long playlistId);

void deleteByPlaylistIdAndMovieId(Long playlistId, Long movieId);

boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public List<MovieInPlaylist> findByPlaylistId(Long playlistId) {
return movieInPlaylistRepository.findByPlaylistId(playlistId);
}

public List<MovieInPlaylist> findByPlaylistIdOrderByCreatedAtDesc(Long playlistId) {
return movieInPlaylistRepository.findByPlaylistIdOrderByCreatedAtDesc(playlistId);
}

public boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId) {
return movieInPlaylistRepository.existsByPlaylistIdAndMovieId(playlistId, movieId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ public void createMovieInPlaylist(@RequestBody MovieInPlaylistRequest.MovieInPla
movieInPlaylistCreateService.createMovieInPlaylist(movieInPlaylistCreateRequest);
}

@GetMapping("/movieInPlaylist/{playlistId}")
@GetMapping("/movieInPlaylist/earliest/{playlistId}")
public List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPlaylist(@PathVariable Long playlistId) {
return movieInPlayListGetService.getMovieInPlayList(playlistId);
}

@GetMapping("/movieInPlaylist/latest/{playlistId}")
public List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPlaylistLatest(@PathVariable Long playlistId) {
return movieInPlayListGetService.getMovieInPlayListLatest(playlistId);
}

@DeleteMapping("/movieInPlaylist/delete")
public void deleteMovieInPlaylist(@RequestBody MovieInPlaylistRequest.MovieInPlaylistDeleteRequest movieInPlaylistDeleteRequest) {
movieInPlaylistDeleteService.deleteMovieInPlayList(movieInPlaylistDeleteRequest);
Expand Down

0 comments on commit fb596d4

Please sign in to comment.