Skip to content

Commit

Permalink
[feat] 보고싶어요 추가/삭제시 플레이리스에 자동 추가/삭제 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
syyling committed Mar 19, 2024
1 parent 00dae74 commit 4ebdce5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import com.mookive.mookive_backend.heart.domain.service.HeartDeleteService;
import com.mookive.mookive_backend.heart.domain.service.HeartQueryService;
import com.mookive.mookive_backend.heart.domain.service.HeartSaveService;
import com.mookive.mookive_backend.heartPlaylist.service.HeartPlaylistQueryService;
import com.mookive.mookive_backend.movie.domain.entity.Movie;
import com.mookive.mookive_backend.movie.domain.service.MovieQueryService;
import com.mookive.mookive_backend.movieInPlaylist.domain.entity.MovieInPlaylist;
import com.mookive.mookive_backend.movieInPlaylist.domain.service.MovieInPlaylistDeleteService;
import com.mookive.mookive_backend.movieInPlaylist.domain.service.MovieInPlaylistSaveService;
import com.mookive.mookive_backend.playlist.domain.entity.Playlist;
import com.mookive.mookive_backend.user.domain.entity.User;
import com.mookive.mookive_backend.user.domain.service.UserQueryService;
import jakarta.transaction.Transactional;
Expand All @@ -22,18 +27,30 @@ public class HeartCreateService {
private final HeartDeleteService heartDeleteService;
private final UserQueryService userQueryService;
private final MovieQueryService movieQueryService;
private final HeartPlaylistQueryService heartPlaylistQueryService;
private final MovieInPlaylistSaveService movieInPlaylistSaveService;
private final MovieInPlaylistDeleteService movieInPlaylistDeleteService;

public void createHeart(Long userId, Long movieId) {
User user = userQueryService.findById(userId);
Movie movie = movieQueryService.findById(movieId);
Playlist playlist = heartPlaylistQueryService.findByUserId(userId).getPlaylist();

if (heartQueryService.existsByUserIdAndMovieId(userId, movieId)) {
heartDeleteService.deleteByUserIdAndMovieId(userId, movieId);
movieInPlaylistDeleteService.deleteByPlaylistIdAndMovieId(playlist.getId(), movieId);
} else {
User user = userQueryService.findById(userId);
Movie movie = movieQueryService.findById(movieId);
Heart heart = Heart.builder()
.user(user)
.movie(movie)
.build();
heartSaveService.save(heart);

MovieInPlaylist movieInPlaylist = MovieInPlaylist.builder()
.movie(movie)
.playlist(playlist)
.build();
movieInPlaylistSaveService.save(movieInPlaylist);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mookive.mookive_backend.heartPlaylist.service;

import com.mookive.mookive_backend.heartPlaylist.domain.HeartPlaylist;
import com.mookive.mookive_backend.heartPlaylist.repository.HeartPlaylistRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Transactional
public class HeartPlaylistQueryService {

private final HeartPlaylistRepository heartPlaylistRepository;

public HeartPlaylist findByUserId(Long userId) {
return heartPlaylistRepository.findByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface MovieInPlaylistRepository extends JpaRepository<MovieInPlaylist, Long> {

List<MovieInPlaylist> findByPlaylistId(Long playlistId);

void deleteByPlaylistIdAndMovieId(Long playlistId, Long movieId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mookive.mookive_backend.movieInPlaylist.domain.service;

import com.mookive.mookive_backend.movieInPlaylist.domain.respository.MovieInPlaylistRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Transactional
public class MovieInPlaylistDeleteService {

private final MovieInPlaylistRepository movieInPlaylistRepository;

public void deleteByPlaylistIdAndMovieId(Long playlistId, Long movieId) {
movieInPlaylistRepository.deleteByPlaylistIdAndMovieId(playlistId, movieId);
}
}

0 comments on commit 4ebdce5

Please sign in to comment.