From fdad4f0b3113bf5f01028afbc7b743855e31b4a0 Mon Sep 17 00:00:00 2001 From: syyling Date: Mon, 18 Mar 2024 18:42:53 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=ED=94=8C=EB=A0=88=EC=9D=B4=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=86=8D=20=EC=98=81=ED=99=94=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MovieInPlaylistResponse.java | 23 ++++++++++ .../mapper/MovieInPlaylistMapper.java | 10 +++++ .../service/MovieInPlayListGetService.java | 43 +++++++++++++++++++ .../MovieInPlaylistRepository.java | 4 ++ .../service/MovieInPlaylistQueryService.java | 21 +++++++++ .../MovieInPlayListController.java | 14 ++++-- .../domain/repository/ReviewRepository.java | 2 + .../domain/service/ReviewQueryService.java | 4 ++ 8 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/dto/response/MovieInPlaylistResponse.java create mode 100644 src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java create mode 100644 src/main/java/com/mookive/mookive_backend/movieInPlaylist/domain/service/MovieInPlaylistQueryService.java 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); + } }