Skip to content

Commit

Permalink
[feat] 플레이리스트 목록 조회 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
syyling committed May 29, 2024
1 parent c1e97c0 commit d6d11db
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface MovieInPlaylistRepository extends JpaRepository<MovieInPlaylist
boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId);

Optional<MovieInPlaylist> findTop1ByPlaylistIdOrderByCreatedAtDesc(Long playlistId);

int countByPlaylistId(Long playlistId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public boolean existsByPlaylistIdAndMovieId(Long playlistId, Long movieId) {
public Optional<MovieInPlaylist> findTop1ByPlaylistIdOrderByCreatedAtDesc(Long playlistId) {
return movieInPlaylistRepository.findTop1ByPlaylistIdOrderByCreatedAtDesc(playlistId);
}

public int countByPlaylistId(Long playlistId) {
return movieInPlaylistRepository.countByPlaylistId(playlistId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -27,11 +28,16 @@ public List<PlaylistResponse.PlaylistGetResponse> getPlaylist(Long userId) {
List<PlaylistResponse.PlaylistGetResponse> playlistGetRequestList = new ArrayList<>();
for (Playlist playlist : playlists) {
String poster = null;
String title = null;
Long playlistId = playlist.getId();
Optional<MovieInPlaylist> optionalMovieInPlaylist = movieInPlaylistQueryService.findTop1ByPlaylistIdOrderByCreatedAtDesc(playlistId);
if(optionalMovieInPlaylist.isPresent())
poster = optionalMovieInPlaylist.get().getMovie().getPoster();
PlaylistResponse.PlaylistGetResponse playlistGetResponse = PlaylistMapper.mapToPlaylistGetResponse(playlist, poster);
Optional<MovieInPlaylist> 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;
Expand Down

0 comments on commit d6d11db

Please sign in to comment.