Skip to content

Commit

Permalink
[feat] #8 isLiked 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed May 15, 2024
1 parent 5ccd519 commit 6726f28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/sopt/cgv/service/MovieService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.sopt.cgv.domain.Movie;
import org.sopt.cgv.repository.HeartsRepository;
import org.sopt.cgv.repository.MovieRepository;
import org.sopt.cgv.service.dto.MovieDetailRequestDto;
import org.springframework.stereotype.Service;
Expand All @@ -11,6 +12,7 @@
public class MovieService {

private final MovieRepository MovieRepository;
private final HeartsRepository heartsRepository;

public Movie findById(Long movieId) {
return MovieRepository.findById(movieId)
Expand All @@ -19,6 +21,8 @@ public Movie findById(Long movieId) {
}

public MovieDetailRequestDto findMovieDetailById(Long movieId) {
return MovieDetailRequestDto.of(findById(movieId));
Movie movie = findById(movieId);
boolean isLiked = heartsRepository.findByMovieId(movieId).isPresent();
return MovieDetailRequestDto.of(movie, isLiked);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

public record MovieDetailRequestDto (
String title,
String script
String script,
boolean isLiked
) {
public static MovieDetailRequestDto of(Movie movie) {
return new MovieDetailRequestDto(movie.getTitle(), movie.getScript());
public static MovieDetailRequestDto of(Movie movie, boolean isLiked) {
return new MovieDetailRequestDto(movie.getTitle(), movie.getScript(), isLiked);
}
}

0 comments on commit 6726f28

Please sign in to comment.