Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 플레이리스트 목록 조회 필드 추가 #46

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading