-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...in/java/com/mookive/mookive_backend/watched/application/service/WatchedCreateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.mookive.mookive_backend.watched.application.service; | ||
|
||
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.MovieInPlaylistDeleteDomainService; | ||
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 com.mookive.mookive_backend.watched.domain.entity.Watched; | ||
import com.mookive.mookive_backend.watched.domain.service.WatchedDeleteService; | ||
import com.mookive.mookive_backend.watched.domain.service.WatchedQueryService; | ||
import com.mookive.mookive_backend.watched.domain.service.WatchedSaveService; | ||
import com.mookive.mookive_backend.watchedPlaylist.domain.service.WatchedPlaylistQueryService; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class WatchedCreateService { | ||
|
||
private final UserQueryService userQueryService; | ||
private final MovieQueryService movieQueryService; | ||
private final WatchedPlaylistQueryService watchedPlaylistQueryService; | ||
private final WatchedQueryService watchedQueryService; | ||
private final WatchedDeleteService watchedDeleteService; | ||
private final MovieInPlaylistDeleteDomainService movieInPlaylistDeleteService; | ||
private final WatchedSaveService watchedSaveService; | ||
private final MovieInPlaylistSaveService movieInPlaylistSaveService; | ||
|
||
public void createWatched(Long userId, Long movieId) { | ||
User user = userQueryService.findById(userId); | ||
Movie movie = movieQueryService.findById(movieId); | ||
Playlist playlist = watchedPlaylistQueryService.findByUserId(userId).getPlaylist(); | ||
|
||
if(watchedQueryService.existsByUserIdAndMovieId(userId, movieId)) { | ||
watchedDeleteService.deleteByUserIdAndMovieId(userId, movieId); | ||
movieInPlaylistDeleteService.deleteByPlaylistIdAndMovieId(playlist.getId(), movieId); | ||
} else { | ||
Watched watched = Watched.builder() | ||
.user(user) | ||
.movie(movie) | ||
.build(); | ||
watchedSaveService.save(watched); | ||
|
||
MovieInPlaylist movieInPlaylist = MovieInPlaylist.builder() | ||
.movie(movie) | ||
.playlist(playlist) | ||
.build(); | ||
movieInPlaylistSaveService.save(movieInPlaylist); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/mookive/mookive_backend/watched/domain/service/WatchedDeleteService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mookive.mookive_backend.watched.domain.service; | ||
|
||
import com.mookive.mookive_backend.watched.domain.repository.WatchedRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Transactional | ||
@RequiredArgsConstructor | ||
@Service | ||
public class WatchedDeleteService { | ||
|
||
private final WatchedRepository watchedRepository; | ||
|
||
public void deleteByUserIdAndMovieId(Long userId, Long movieId) { | ||
watchedRepository.deleteByUserIdAndMovieId(userId, movieId); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/mookive/mookive_backend/watched/domain/service/WatchedQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mookive.mookive_backend.watched.domain.service; | ||
|
||
import com.mookive.mookive_backend.watched.domain.repository.WatchedRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Transactional | ||
@RequiredArgsConstructor | ||
@Service | ||
public class WatchedQueryService { | ||
|
||
private final WatchedRepository watchedRepository; | ||
|
||
public boolean existsByUserIdAndMovieId(Long userId, Long movieId) { | ||
return watchedRepository.existsByUserIdAndMovieId(userId, movieId); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mookive/mookive_backend/watched/domain/service/WatchedSaveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mookive.mookive_backend.watched.domain.service; | ||
|
||
|
||
import com.mookive.mookive_backend.watched.domain.entity.Watched; | ||
import com.mookive.mookive_backend.watched.domain.repository.WatchedRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Transactional | ||
@RequiredArgsConstructor | ||
@Service | ||
public class WatchedSaveService { | ||
|
||
private final WatchedRepository watchedRepository; | ||
|
||
public void save(Watched watched) { | ||
watchedRepository.save(watched); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mookive/mookive_backend/watched/presentation/WatchedController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mookive.mookive_backend.watched.presentation; | ||
|
||
|
||
import com.mookive.mookive_backend.watched.application.service.WatchedCreateService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class WatchedController { | ||
|
||
private final WatchedCreateService watchedCreateService; | ||
|
||
@PostMapping("/watched") | ||
public void createWatched(@RequestParam Long userId, @RequestParam Long movieId) { | ||
watchedCreateService.createWatched(userId, movieId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...m/mookive/mookive_backend/watchedPlaylist/domain/service/WatchedPlaylistQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mookive.mookive_backend.watchedPlaylist.domain.service; | ||
|
||
import com.mookive.mookive_backend.watchedPlaylist.domain.entity.WatchedPlaylist; | ||
import com.mookive.mookive_backend.watchedPlaylist.domain.repository.WatchedPlaylistRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class WatchedPlaylistQueryService { | ||
|
||
private final WatchedPlaylistRepository watchedPlaylistRepository; | ||
|
||
public WatchedPlaylist findByUserId(Long userId) { | ||
return watchedPlaylistRepository.findByUserId(userId); | ||
} | ||
} |