Skip to content

Commit

Permalink
[feat] 플레이리스트 속 영화 리스트 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
syyling committed Mar 18, 2024
1 parent ea2817d commit fdad4f0
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPlayList(Long playlistId) {
Playlist playlist = playlistQueryService.findById(playlistId);
Long userId = playlist.getUser().getId();

List<MovieInPlaylist> movieInPlaylistList = movieInPlaylistQueryService.findByPlaylistId(playlistId);
List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> 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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MovieInPlaylist, Long> {

List<MovieInPlaylist> findByPlaylistId(Long playlistId);
}
Original file line number Diff line number Diff line change
@@ -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<MovieInPlaylist> findByPlaylistId(Long playlistId) {
return movieInPlaylistRepository.findByPlaylistId(playlistId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPlaylist(@PathVariable Long playlistId) {
return movieInPlayListGetService.getMovieInPlayList(playlistId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface ReviewRepository extends JpaRepository<Review, Long> {

Review findByUserIdAndMovieId(Long userId, Long movieId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit fdad4f0

Please sign in to comment.