diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlaylistCreateService.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlaylistCreateService.java index 7dcd841..74d3f21 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlaylistCreateService.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlaylistCreateService.java @@ -4,6 +4,8 @@ import com.mookive.mookive_backend.common.exception.Error; import com.mookive.mookive_backend.movie.domain.entity.Movie; import com.mookive.mookive_backend.movie.domain.service.MovieQueryService; +import com.mookive.mookive_backend.movie.domain.service.MovieSaveService; +import com.mookive.mookive_backend.movie.infra.service.MovieEntityGetService; import com.mookive.mookive_backend.movieInPlaylist.application.dto.request.MovieInPlaylistRequest; import com.mookive.mookive_backend.movieInPlaylist.application.mapper.MovieInPlaylistMapper; import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist; @@ -24,6 +26,8 @@ public class MovieInPlaylistCreateService { private final MovieQueryService movieQueryService; private final MovieInPlaylistSaveService movieInPlaylistSaveService; private final MovieInPlaylistQueryService movieInPlaylistQueryService; + private final MovieEntityGetService movieEntityGetService; + private final MovieSaveService movieSaveService; /** todo: "해당 영화가 이미 플레이리스트에 존재합니다" 라는 에러 메시지를 반환하도록 수정 @@ -32,6 +36,10 @@ public void createMovieInPlaylist(MovieInPlaylistRequest.MovieInPlaylistCreateRe Long playlistId = movieInPlaylistCreateRequest.getPlaylistId(); String tmdbId = movieInPlaylistCreateRequest.getTmdbId(); Movie movie = movieQueryService.findByTmdbId(tmdbId); + if(movie == null) { + movie = movieEntityGetService.searchMovie(tmdbId); + movieSaveService.save(movie); + } if(movieInPlaylistQueryService.existsByPlaylistIdAndMovieId(playlistId, movie.getId())) { throw new BusinessException(Error.PLAYLIST_MOVIE_DUPLICATION); }