diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/dto/response/MovieInPlaylistResponse.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/dto/response/MovieInPlaylistResponse.java new file mode 100644 index 0000000..8f51788 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/dto/response/MovieInPlaylistResponse.java @@ -0,0 +1,23 @@ +package com.mookive.mookive_backend.movieInPlaylist.application.dto.response; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class MovieInPlaylistResponse { + + @Getter + @NoArgsConstructor + public static class MovieInPlaylistDefaultResponse { + private String title; + private String poster; + private String rating; + + @Builder + public MovieInPlaylistDefaultResponse(String title, String poster, String rating) { + this.title = title; + this.poster = poster; + this.rating = rating; + } + } +} diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/mapper/MovieInPlaylistMapper.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/mapper/MovieInPlaylistMapper.java index 1a135f2..ae642b1 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/mapper/MovieInPlaylistMapper.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/mapper/MovieInPlaylistMapper.java @@ -1,6 +1,7 @@ package com.mookive.mookive_backend.movieInPlaylist.application.mapper; import com.mookive.mookive_backend.movie.domain.entity.Movie; +import com.mookive.mookive_backend.movieInPlaylist.application.dto.response.MovieInPlaylistResponse; import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; import com.mookive.mookive_backend.playlist.domain.entity.Playlist; @@ -12,4 +13,13 @@ public static MovieInPlaylist mapToMovieInPlaylist(Movie movie, Playlist playlis .playlist(playlist) .build(); } + + public static MovieInPlaylistResponse.MovieInPlaylistDefaultResponse mapToMovieInPlaylistDefaultResponse + (MovieInPlaylist movieInPlaylist, String rating) { + return MovieInPlaylistResponse.MovieInPlaylistDefaultResponse.builder() + .title(movieInPlaylist.getMovie().getTitle()) + .poster(movieInPlaylist.getMovie().getPoster()) + .rating(rating) + .build(); + } } 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 new file mode 100644 index 0000000..a09e94c --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java @@ -0,0 +1,43 @@ +package com.mookive.mookive_backend.movieInPlaylist.application.service; + +import com.mookive.mookive_backend.movieInPlaylist.application.dto.response.MovieInPlaylistResponse; +import com.mookive.mookive_backend.movieInPlaylist.application.mapper.MovieInPlaylistMapper; +import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; +import com.mookive.mookive_backend.movieInPlaylist.domain.service.MovieInPlaylistQueryService; +import com.mookive.mookive_backend.playlist.domain.entity.Playlist; +import com.mookive.mookive_backend.playlist.domain.service.PlaylistQueryService; +import com.mookive.mookive_backend.review.domain.entity.Review; +import com.mookive.mookive_backend.review.domain.service.ReviewQueryService; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +@Transactional +public class MovieInPlayListGetService { + + private final MovieInPlaylistQueryService movieInPlaylistQueryService; + private final PlaylistQueryService playlistQueryService; + private final ReviewQueryService reviewQueryService; + + public List getMovieInPlayList(Long playlistId) { + Playlist playlist = playlistQueryService.findById(playlistId); + Long userId = playlist.getUser().getId(); + + List movieInPlaylistList = movieInPlaylistQueryService.findByPlaylistId(playlistId); + List movieInPlaylistDefaultResponseList = movieInPlaylistList.stream().map(movieInPlaylist -> + { + Long movieId = movieInPlaylist.getMovie().getId(); + Review review = reviewQueryService.findByUserIdAndMovieId(userId, movieId); + String rating = review != null ? review.getRating() : null; + 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 befbaa1..a184fd8 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 @@ -3,5 +3,9 @@ import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface MovieInPlaylistRepository extends JpaRepository { + + List findByPlaylistId(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 new file mode 100644 index 0000000..97e0bc9 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/service/MovieInPlaylistQueryService.java @@ -0,0 +1,21 @@ +package com.mookive.mookive_backend.movieInPlaylist.domain.service; + +import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; +import com.mookive.mookive_backend.movieInPlaylist.domain.respository.MovieInPlaylistRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@Transactional +@RequiredArgsConstructor +public class MovieInPlaylistQueryService { + + private final MovieInPlaylistRepository movieInPlaylistRepository; + + public List findByPlaylistId(Long playlistId) { + return movieInPlaylistRepository.findByPlaylistId(playlistId); + } +} 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 c70a40f..937c4a1 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 @@ -2,20 +2,28 @@ import com.mookive.mookive_backend.movieInPlaylist.application.dto.request.MovieInPlaylistRequest; +import com.mookive.mookive_backend.movieInPlaylist.application.dto.response.MovieInPlaylistResponse; +import com.mookive.mookive_backend.movieInPlaylist.application.service.MovieInPlayListGetService; import com.mookive.mookive_backend.movieInPlaylist.application.service.MovieInPlaylistCreateService; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequiredArgsConstructor public class MovieInPlayListController { private final MovieInPlaylistCreateService movieInPlaylistCreateService; + private final MovieInPlayListGetService movieInPlayListGetService; @PostMapping("/movieInPlaylist") public void createMovieInPlaylist(@RequestBody MovieInPlaylistRequest.MovieInPlaylistCreateRequest movieInPlaylistCreateRequest) { movieInPlaylistCreateService.createMovieInPlaylist(movieInPlaylistCreateRequest); } + + @GetMapping("/movieInPlaylist/{playlistId}") + public List getMovieInPlaylist(@PathVariable Long playlistId) { + return movieInPlayListGetService.getMovieInPlayList(playlistId); + } } diff --git a/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java b/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java index 901b317..cb2d7f2 100644 --- a/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java +++ b/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java @@ -4,4 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface ReviewRepository extends JpaRepository { + + Review findByUserIdAndMovieId(Long userId, Long movieId); } diff --git a/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java b/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java index dd17ce4..3c8a4e2 100644 --- a/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java +++ b/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java @@ -17,4 +17,8 @@ public Review findById(Long reviewId) { return reviewRepository.findById(reviewId) .orElseThrow(() -> new IllegalArgumentException("Review not found")); } + + public Review findByUserIdAndMovieId(Long userId, Long movieId) { + return reviewRepository.findByUserIdAndMovieId(userId, movieId); + } }