From 59d8dcf41b763a03f0d64acf4bd6d50cd76a5c35 Mon Sep 17 00:00:00 2001 From: syyling Date: Thu, 4 Apr 2024 14:31:56 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[feat]=20Movie=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20tagline=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mookive/mookive_backend/movie/domain/entity/Movie.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java b/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java index dbc4eeb..6cb4ffb 100644 --- a/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java +++ b/src/main/java/com/mookive/mookive_backend/movie/domain/entity/Movie.java @@ -22,11 +22,12 @@ public class Movie { private String poster; private String nation; private String tmdbId; + private String tagline; @Builder public Movie(String title, String year, String director, String genre, - String plot, String poster, String nation, String tmdbId) { + String plot, String poster, String nation, String tmdbId, String tagline) { this.title = title; this.year = year; this.director = director; @@ -35,5 +36,6 @@ public Movie(String title, String year, String director, String genre, this.poster = poster; this.nation = nation; this.tmdbId = tmdbId; + this.tagline = tagline; } } From a10bbcb8c396096e8f07e29f134cfd2e1cd35849 Mon Sep 17 00:00:00 2001 From: syyling Date: Thu, 4 Apr 2024 14:32:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[feat]=20=EC=98=81=ED=99=94=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20?= =?UTF-8?q?tagline=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../movie/application/dto/response/MovieResponse.java | 5 ++++- .../movie/application/mapper/MovieMapper.java | 1 + .../mookive_backend/movie/infra/MovieSearchService.java | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mookive/mookive_backend/movie/application/dto/response/MovieResponse.java b/src/main/java/com/mookive/mookive_backend/movie/application/dto/response/MovieResponse.java index 3b88d8e..53fced2 100644 --- a/src/main/java/com/mookive/mookive_backend/movie/application/dto/response/MovieResponse.java +++ b/src/main/java/com/mookive/mookive_backend/movie/application/dto/response/MovieResponse.java @@ -17,9 +17,11 @@ public static class MovieDetailResponse { private String plot; private String poster; private String nation; + private String tagline; @Builder - public MovieDetailResponse(String title, String director, String genre, String year, String plot, String poster, String nation) { + public MovieDetailResponse(String title, String director, String genre, String year, String plot, + String poster, String nation, String tagline) { this.title = title; this.director = director; this.genre = genre; @@ -27,6 +29,7 @@ public MovieDetailResponse(String title, String director, String genre, String y this.plot = plot; this.poster = poster; this.nation = nation; + this.tagline = tagline; } } } diff --git a/src/main/java/com/mookive/mookive_backend/movie/application/mapper/MovieMapper.java b/src/main/java/com/mookive/mookive_backend/movie/application/mapper/MovieMapper.java index 9c8b45b..d614156 100644 --- a/src/main/java/com/mookive/mookive_backend/movie/application/mapper/MovieMapper.java +++ b/src/main/java/com/mookive/mookive_backend/movie/application/mapper/MovieMapper.java @@ -14,6 +14,7 @@ public static MovieResponse.MovieDetailResponse mapToMovieDetailResponse(Movie m .plot(movie.getPlot()) .nation(movie.getNation()) .poster(movie.getPoster()) + .tagline(movie.getTagline()) .build(); } } diff --git a/src/main/java/com/mookive/mookive_backend/movie/infra/MovieSearchService.java b/src/main/java/com/mookive/mookive_backend/movie/infra/MovieSearchService.java index ad17214..bf202f5 100644 --- a/src/main/java/com/mookive/mookive_backend/movie/infra/MovieSearchService.java +++ b/src/main/java/com/mookive/mookive_backend/movie/infra/MovieSearchService.java @@ -30,6 +30,7 @@ public Movie searchMovie(String tmdbId) { .poster(tmdbResponse.getPoster()) .nation(koficResponse.getNation()) .director(koficResponse.getDirector()) + .tagline(tmdbResponse.getTagline()) .build(); } @@ -46,6 +47,7 @@ private TmdbResponse getTmdbResponse(String tmdbMovieId) { Object plot = jsonObject.get("overview"); Object poster = "https://image.tmdb.org/t/p/original" + jsonObject.get("poster_path"); Object year = jsonObject.get("release_date").toString().substring(0, 4); + Object tagline = jsonObject.get("tagline"); return TmdbResponse.builder() .title(title.toString()) @@ -53,6 +55,7 @@ private TmdbResponse getTmdbResponse(String tmdbMovieId) { .genre(genre.toString()) .plot(plot.toString()) .poster(poster.toString()) + .tagline(tagline.toString()) .build(); } @@ -84,14 +87,16 @@ private static class TmdbResponse { private String genre; private String plot; private String poster; + private String tagline; @Builder - public TmdbResponse(String title, String year, String genre, String plot, String poster) { + public TmdbResponse(String title, String year, String genre, String plot, String poster, String tagline) { this.title = title; this.year = year; this.genre = genre; this.plot = plot; this.poster = poster; + this.tagline = tagline; } } From 13ecd0cde9de2f2e1ef0fe837b798b3b92ea7a08 Mon Sep 17 00:00:00 2001 From: syyling Date: Thu, 4 Apr 2024 14:34:18 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[refactor]=20Review=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EB=AA=85=20Record=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/mapper/KeywordMapper.java | 6 +- .../keyword/domain/entity/Keyword.java | 10 +-- .../domain/repository/KeywordRepository.java | 4 +- .../domain/service/KeywordDeleteService.java | 4 +- .../domain/service/KeywordQueryService.java | 4 +- .../service/MovieInPlayListGetService.java | 12 ++-- .../dto/request/RecordRequest.java} | 8 +-- .../dto/response/RecordResponse.java} | 8 +-- .../application/mapper/RecordMapper.java | 31 +++++++++ .../service/RecordCreateService.java | 69 +++++++++++++++++++ .../service/RecordGetService.java} | 22 +++--- .../domain/entity/Record.java} | 8 +-- .../domain/repository/RecordRepository.java | 11 +++ .../domain/service/RecordQueryService.java | 27 ++++++++ .../domain/service/RecordSaveService.java | 19 +++++ .../record/presentation/RecordController.java | 27 ++++++++ .../application/mapper/ReviewMapper.java | 31 --------- .../service/ReviewCreateService.java | 68 ------------------ .../domain/repository/ReviewRepository.java | 11 --- .../domain/service/ReviewQueryService.java | 27 -------- .../domain/service/ReviewSaveService.java | 19 ----- .../review/presentation/ReviewController.java | 27 -------- 22 files changed, 227 insertions(+), 226 deletions(-) rename src/main/java/com/mookive/mookive_backend/{review/application/dto/request/ReviewRequest.java => record/application/dto/request/RecordRequest.java} (77%) rename src/main/java/com/mookive/mookive_backend/{review/application/dto/response/ReviewResponse.java => record/application/dto/response/RecordResponse.java} (71%) create mode 100644 src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java create mode 100644 src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java rename src/main/java/com/mookive/mookive_backend/{review/application/service/ReviewGetService.java => record/application/service/RecordGetService.java} (50%) rename src/main/java/com/mookive/mookive_backend/{review/domain/entity/Review.java => record/domain/entity/Record.java} (82%) create mode 100644 src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java create mode 100644 src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java create mode 100644 src/main/java/com/mookive/mookive_backend/record/domain/service/RecordSaveService.java create mode 100644 src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java delete mode 100644 src/main/java/com/mookive/mookive_backend/review/application/mapper/ReviewMapper.java delete mode 100644 src/main/java/com/mookive/mookive_backend/review/application/service/ReviewCreateService.java delete mode 100644 src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java delete mode 100644 src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java delete mode 100644 src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewSaveService.java delete mode 100644 src/main/java/com/mookive/mookive_backend/review/presentation/ReviewController.java diff --git a/src/main/java/com/mookive/mookive_backend/keyword/application/mapper/KeywordMapper.java b/src/main/java/com/mookive/mookive_backend/keyword/application/mapper/KeywordMapper.java index ebea6f6..4212db5 100644 --- a/src/main/java/com/mookive/mookive_backend/keyword/application/mapper/KeywordMapper.java +++ b/src/main/java/com/mookive/mookive_backend/keyword/application/mapper/KeywordMapper.java @@ -1,13 +1,13 @@ package com.mookive.mookive_backend.keyword.application.mapper; import com.mookive.mookive_backend.keyword.domain.entity.Keyword; -import com.mookive.mookive_backend.review.domain.entity.Review; +import com.mookive.mookive_backend.record.domain.entity.Record; public class KeywordMapper { - public static Keyword mapToKeyword(Review review, String word, Long movieId) { + public static Keyword mapToKeyword(Record record, String word, Long movieId) { return Keyword.builder() - .review(review) + .record(record) .word(word) .movieId(movieId) .build(); diff --git a/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java b/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java index 18c53a2..02e7b34 100644 --- a/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java +++ b/src/main/java/com/mookive/mookive_backend/keyword/domain/entity/Keyword.java @@ -1,6 +1,6 @@ package com.mookive.mookive_backend.keyword.domain.entity; -import com.mookive.mookive_backend.review.domain.entity.Review; +import com.mookive.mookive_backend.record.domain.entity.Record; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -16,15 +16,15 @@ public class Keyword { private Long id; @ManyToOne - @JoinColumn(name = "review_id") - private Review review; + @JoinColumn(name = "record") + private Record record; private String word; private Long movieId; @Builder - public Keyword(Review review, String word, Long movieId) { - this.review = review; + public Keyword(Record record, String word, Long movieId) { + this.record = record; this.word = word; this.movieId = movieId; } diff --git a/src/main/java/com/mookive/mookive_backend/keyword/domain/repository/KeywordRepository.java b/src/main/java/com/mookive/mookive_backend/keyword/domain/repository/KeywordRepository.java index b054b23..7316111 100644 --- a/src/main/java/com/mookive/mookive_backend/keyword/domain/repository/KeywordRepository.java +++ b/src/main/java/com/mookive/mookive_backend/keyword/domain/repository/KeywordRepository.java @@ -7,7 +7,7 @@ public interface KeywordRepository extends JpaRepository { - List findByReviewId(Long reviewId); + List findByRecordId(Long recordId); - void deleteAllByReviewId(Long reviewId); + void deleteAllByRecordId(Long recordId); } diff --git a/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordDeleteService.java b/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordDeleteService.java index 3f69f6f..cf54856 100644 --- a/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordDeleteService.java +++ b/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordDeleteService.java @@ -13,7 +13,7 @@ public class KeywordDeleteService { private final KeywordRepository keywordRepository; - public void deleteAllByReviewId(Long reviewId) { - keywordRepository.deleteAllByReviewId(reviewId); + public void deleteAllByRecordId(Long recordId) { + keywordRepository.deleteAllByRecordId(recordId); } } diff --git a/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordQueryService.java b/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordQueryService.java index ba9a974..ba6cf17 100644 --- a/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordQueryService.java +++ b/src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordQueryService.java @@ -15,7 +15,7 @@ public class KeywordQueryService { private final KeywordRepository keywordRepository; - public List findByReviewId(Long reviewId) { - return keywordRepository.findByReviewId(reviewId); + public List findByRecordId(Long recordId) { + return keywordRepository.findByRecordId(recordId); } } diff --git a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java index 50c4113..93184fe 100644 --- a/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java +++ b/src/main/java/com/mookive/mookive_backend/movieInPlaylist/application/service/MovieInPlayListGetService.java @@ -6,8 +6,8 @@ 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 com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.record.domain.service.RecordQueryService; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,7 +23,7 @@ public class MovieInPlayListGetService { private final MovieInPlaylistQueryService movieInPlaylistQueryService; private final PlaylistQueryService playlistQueryService; - private final ReviewQueryService reviewQueryService; + private final RecordQueryService recordQueryService; public List getMovieInPlayList(Long playlistId) { Playlist playlist = playlistQueryService.findById(playlistId); @@ -33,10 +33,10 @@ public List getMovieInPl List movieInPlaylistDefaultResponseList = movieInPlaylistList.stream().map(movieInPlaylist -> { Long movieId = movieInPlaylist.getMovie().getId(); - Optional review = reviewQueryService.findByUserIdAndMovieId(userId, movieId); + Optional record = recordQueryService.findByUserIdAndMovieId(userId, movieId); String rating = null; - if(review.isPresent()) { - rating = review.get().getRating(); + if(record.isPresent()) { + rating = record.get().getRating(); } return MovieInPlaylistMapper.mapToMovieInPlaylistDefaultResponse(movieInPlaylist, rating); }).collect(Collectors.toList()); diff --git a/src/main/java/com/mookive/mookive_backend/review/application/dto/request/ReviewRequest.java b/src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java similarity index 77% rename from src/main/java/com/mookive/mookive_backend/review/application/dto/request/ReviewRequest.java rename to src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java index 6248702..3200a00 100644 --- a/src/main/java/com/mookive/mookive_backend/review/application/dto/request/ReviewRequest.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java @@ -1,4 +1,4 @@ -package com.mookive.mookive_backend.review.application.dto.request; +package com.mookive.mookive_backend.record.application.dto.request; import lombok.Builder; import lombok.Getter; @@ -7,11 +7,11 @@ import java.time.LocalDate; import java.util.ArrayList; -public class ReviewRequest { +public class RecordRequest { @Getter @NoArgsConstructor - public static class ReviewCreateRequest { + public static class RecordCreateRequest { private Long movieId; private Long userId; private String rating; @@ -21,7 +21,7 @@ public static class ReviewCreateRequest { @Builder - public ReviewCreateRequest(Long movieId, Long userId, String rating, + public RecordCreateRequest(Long movieId, Long userId, String rating, String text, LocalDate date, ArrayList keywords) { this.movieId = movieId; this.userId = userId; diff --git a/src/main/java/com/mookive/mookive_backend/review/application/dto/response/ReviewResponse.java b/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java similarity index 71% rename from src/main/java/com/mookive/mookive_backend/review/application/dto/response/ReviewResponse.java rename to src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java index 4d8f3eb..12af934 100644 --- a/src/main/java/com/mookive/mookive_backend/review/application/dto/response/ReviewResponse.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java @@ -1,4 +1,4 @@ -package com.mookive.mookive_backend.review.application.dto.response; +package com.mookive.mookive_backend.record.application.dto.response; import lombok.Builder; import lombok.Getter; @@ -7,18 +7,18 @@ import java.time.LocalDate; import java.util.List; -public class ReviewResponse { +public class RecordResponse { @Getter @NoArgsConstructor - public static class ReviewDetailResponse { + public static class RecordDetailResponse{ private String rating; private String text; private LocalDate date; private List keywords; @Builder - public ReviewDetailResponse(String rating, String text, LocalDate date, List keywords) { + public RecordDetailResponse(String rating, String text, LocalDate date, List keywords) { this.rating = rating; this.text = text; this.date = date; diff --git a/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java b/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java new file mode 100644 index 0000000..1e14947 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java @@ -0,0 +1,31 @@ +package com.mookive.mookive_backend.record.application.mapper; + +import com.mookive.mookive_backend.movie.domain.entity.Movie; +import com.mookive.mookive_backend.record.application.dto.request.RecordRequest; +import com.mookive.mookive_backend.record.application.dto.response.RecordResponse; +import com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.user.domain.entity.User; + +import java.util.List; + +public class RecordMapper { + + public static Record mapToRecord(RecordRequest.RecordCreateRequest recordCreateRequest, Movie movie, User user) { + return Record.builder() + .movie(movie) + .user(user) + .rating(recordCreateRequest.getRating()) + .text(recordCreateRequest.getText()) + .date(recordCreateRequest.getDate()) + .build(); + } + + public static RecordResponse.RecordDetailResponse mapToRecordDetailResponse(Record record, List keywords) { + return RecordResponse.RecordDetailResponse.builder() + .rating(record.getRating()) + .text(record.getText()) + .date(record.getDate()) + .keywords(keywords) + .build(); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java b/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java new file mode 100644 index 0000000..6c61e21 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java @@ -0,0 +1,69 @@ +package com.mookive.mookive_backend.record.application.service; + + +import com.mookive.mookive_backend.keyword.application.mapper.KeywordMapper; +import com.mookive.mookive_backend.keyword.domain.entity.Keyword; +import com.mookive.mookive_backend.keyword.domain.service.KeywordDeleteService; +import com.mookive.mookive_backend.keyword.domain.service.KeywordSaveService; +import com.mookive.mookive_backend.movie.domain.entity.Movie; +import com.mookive.mookive_backend.movie.domain.service.MovieQueryService; +import com.mookive.mookive_backend.record.application.dto.request.RecordRequest; +import com.mookive.mookive_backend.record.application.mapper.RecordMapper; +import com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.record.domain.service.RecordQueryService; +import com.mookive.mookive_backend.record.domain.service.RecordQueryService; +import com.mookive.mookive_backend.record.domain.service.RecordSaveService; +import com.mookive.mookive_backend.user.domain.entity.User; +import com.mookive.mookive_backend.user.domain.service.UserQueryService; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Transactional +public class RecordCreateService { + + private final MovieQueryService movieQueryService; + private final UserQueryService userQueryService; + private final RecordSaveService recordSaveService; + private final KeywordSaveService keywordSaveService; + private final KeywordDeleteService keywordDeleteService; + private final RecordQueryService recordQueryService; + + public void createRecord(RecordRequest.RecordCreateRequest recordCreateRequest) { + Long movieId = recordCreateRequest.getMovieId(); + Long userId = recordCreateRequest.getUserId(); + Optional optionalRecord = recordQueryService.findByUserIdAndMovieId(userId, movieId); + if(optionalRecord.isPresent()){ + Record record = optionalRecord.get(); + LocalDate date = recordCreateRequest.getDate(); + String rating = recordCreateRequest.getRating(); + String text = recordCreateRequest.getText(); + ArrayList keywords = recordCreateRequest.getKeywords(); + record.updateRecord(rating, text, date); + keywordDeleteService.deleteAllByRecordId(record.getId()); + saveKeywords(keywords, record, movieId); + } + else { + Movie movie = movieQueryService.findById(movieId); + User user = userQueryService.findById(userId); + Record record = RecordMapper.mapToRecord(recordCreateRequest, movie, user); + recordSaveService.saveRecord(record); + ArrayList keywords = recordCreateRequest.getKeywords(); + saveKeywords(keywords, record, movieId); + } + } + + private void saveKeywords(ArrayList keywords, Record record, Long movieId) { + for(String word : keywords){ + Keyword keyword = KeywordMapper.mapToKeyword(record, word, movieId); + keywordSaveService.saveKeyword(keyword); + } + } +} diff --git a/src/main/java/com/mookive/mookive_backend/review/application/service/ReviewGetService.java b/src/main/java/com/mookive/mookive_backend/record/application/service/RecordGetService.java similarity index 50% rename from src/main/java/com/mookive/mookive_backend/review/application/service/ReviewGetService.java rename to src/main/java/com/mookive/mookive_backend/record/application/service/RecordGetService.java index 2cc2654..46019b8 100644 --- a/src/main/java/com/mookive/mookive_backend/review/application/service/ReviewGetService.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/service/RecordGetService.java @@ -1,11 +1,11 @@ -package com.mookive.mookive_backend.review.application.service; +package com.mookive.mookive_backend.record.application.service; import com.mookive.mookive_backend.keyword.domain.entity.Keyword; import com.mookive.mookive_backend.keyword.domain.service.KeywordQueryService; -import com.mookive.mookive_backend.review.application.dto.response.ReviewResponse; -import com.mookive.mookive_backend.review.application.mapper.ReviewMapper; -import com.mookive.mookive_backend.review.domain.entity.Review; -import com.mookive.mookive_backend.review.domain.service.ReviewQueryService; +import com.mookive.mookive_backend.record.application.dto.response.RecordResponse; +import com.mookive.mookive_backend.record.application.mapper.RecordMapper; +import com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.record.domain.service.RecordQueryService; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -16,18 +16,18 @@ @Service @RequiredArgsConstructor @Transactional -public class ReviewGetService { +public class RecordGetService { - private final ReviewQueryService reviewQueryService; + private final RecordQueryService recordQueryService; private final KeywordQueryService keywordQueryService; - public ReviewResponse.ReviewDetailResponse getReview(Long reviewId) { - Review review = reviewQueryService.findById(reviewId); - List keywordList = keywordQueryService.findByReviewId(reviewId); + public RecordResponse.RecordDetailResponse getRecord(Long recordId) { + Record record = recordQueryService.findById(recordId); + List keywordList = keywordQueryService.findByRecordId(recordId); List keywords= new ArrayList<>(); for(Keyword keyword : keywordList){ keywords.add(keyword.getWord()); } - return ReviewMapper.mapToReviewDetailResponse(review, keywords); + return RecordMapper.mapToRecordDetailResponse(record, keywords); } } diff --git a/src/main/java/com/mookive/mookive_backend/review/domain/entity/Review.java b/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java similarity index 82% rename from src/main/java/com/mookive/mookive_backend/review/domain/entity/Review.java rename to src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java index c639e0f..e235543 100644 --- a/src/main/java/com/mookive/mookive_backend/review/domain/entity/Review.java +++ b/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java @@ -1,4 +1,4 @@ -package com.mookive.mookive_backend.review.domain.entity; +package com.mookive.mookive_backend.record.domain.entity; import com.mookive.mookive_backend.movie.domain.entity.Movie; @@ -14,7 +14,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Review { +public class Record { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -32,7 +32,7 @@ public class Review { private Movie movie; @Builder - public Review(String rating, String text, LocalDate date, User user, Movie movie) { + public Record(String rating, String text, LocalDate date, User user, Movie movie) { this.rating = rating; this.text = text; this.date = date; @@ -40,7 +40,7 @@ public Review(String rating, String text, LocalDate date, User user, Movie movie this.movie = movie; } - public void updateReview(String rating, String text, LocalDate date) { + public void updateRecord(String rating, String text, LocalDate date) { this.rating = rating; this.text = text; this.date = date; diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java b/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java new file mode 100644 index 0000000..9887baf --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java @@ -0,0 +1,11 @@ +package com.mookive.mookive_backend.record.domain.repository; + +import com.mookive.mookive_backend.record.domain.entity.Record; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface RecordRepository extends JpaRepository { + + Optional findByUserIdAndMovieId(Long userId, Long movieId);; +} diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java b/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java new file mode 100644 index 0000000..625d614 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java @@ -0,0 +1,27 @@ +package com.mookive.mookive_backend.record.domain.service; + +import com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.record.domain.repository.RecordRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Transactional +public class RecordQueryService { + + private final RecordRepository recordRepository; + + public Record findById(Long recordId) { + return recordRepository.findById(recordId) + .orElseThrow(() -> new IllegalArgumentException("Record not found")); + } + + public Optional findByUserIdAndMovieId(Long userId, Long movieId) { + return recordRepository.findByUserIdAndMovieId(userId, movieId); + } + +} diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordSaveService.java b/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordSaveService.java new file mode 100644 index 0000000..40e3df2 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordSaveService.java @@ -0,0 +1,19 @@ +package com.mookive.mookive_backend.record.domain.service; + +import com.mookive.mookive_backend.record.domain.entity.Record; +import com.mookive.mookive_backend.record.domain.repository.RecordRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +@Transactional +public class RecordSaveService { + + private final RecordRepository recordRepository; + + public void saveRecord(Record record) { + recordRepository.save(record); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java b/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java new file mode 100644 index 0000000..ea410af --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java @@ -0,0 +1,27 @@ +package com.mookive.mookive_backend.record.presentation; + +import com.mookive.mookive_backend.record.application.dto.request.RecordRequest; +import com.mookive.mookive_backend.record.application.dto.response.RecordResponse; +import com.mookive.mookive_backend.record.application.service.RecordCreateService; +import com.mookive.mookive_backend.record.application.service.RecordGetService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +public class RecordController { + + private final RecordCreateService recordCreateService; + private final RecordGetService recordGetService; + + @PostMapping("/record") + public void createRecord(@RequestBody RecordRequest.RecordCreateRequest recordCreateRequest) { + recordCreateService.createRecord(recordCreateRequest); + } + + @GetMapping("/record/{recordId}") + public RecordResponse.RecordDetailResponse getRecord(@PathVariable Long recordId) { + return recordGetService.getRecord(recordId); + } + +} diff --git a/src/main/java/com/mookive/mookive_backend/review/application/mapper/ReviewMapper.java b/src/main/java/com/mookive/mookive_backend/review/application/mapper/ReviewMapper.java deleted file mode 100644 index 5d71690..0000000 --- a/src/main/java/com/mookive/mookive_backend/review/application/mapper/ReviewMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.mookive.mookive_backend.review.application.mapper; - -import com.mookive.mookive_backend.movie.domain.entity.Movie; -import com.mookive.mookive_backend.review.application.dto.request.ReviewRequest; -import com.mookive.mookive_backend.review.application.dto.response.ReviewResponse; -import com.mookive.mookive_backend.review.domain.entity.Review; -import com.mookive.mookive_backend.user.domain.entity.User; - -import java.util.List; - -public class ReviewMapper { - - public static Review mapToReview(ReviewRequest.ReviewCreateRequest reviewCreateRequest, Movie movie, User user) { - return Review.builder() - .movie(movie) - .user(user) - .rating(reviewCreateRequest.getRating()) - .text(reviewCreateRequest.getText()) - .date(reviewCreateRequest.getDate()) - .build(); - } - - public static ReviewResponse.ReviewDetailResponse mapToReviewDetailResponse(Review review, List keywords) { - return ReviewResponse.ReviewDetailResponse.builder() - .rating(review.getRating()) - .text(review.getText()) - .date(review.getDate()) - .keywords(keywords) - .build(); - } -} diff --git a/src/main/java/com/mookive/mookive_backend/review/application/service/ReviewCreateService.java b/src/main/java/com/mookive/mookive_backend/review/application/service/ReviewCreateService.java deleted file mode 100644 index 0a34372..0000000 --- a/src/main/java/com/mookive/mookive_backend/review/application/service/ReviewCreateService.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.mookive.mookive_backend.review.application.service; - - -import com.mookive.mookive_backend.keyword.application.mapper.KeywordMapper; -import com.mookive.mookive_backend.keyword.domain.entity.Keyword; -import com.mookive.mookive_backend.keyword.domain.repository.KeywordRepository; -import com.mookive.mookive_backend.keyword.domain.service.KeywordDeleteService; -import com.mookive.mookive_backend.keyword.domain.service.KeywordSaveService; -import com.mookive.mookive_backend.movie.domain.entity.Movie; -import com.mookive.mookive_backend.movie.domain.service.MovieQueryService; -import com.mookive.mookive_backend.review.application.dto.request.ReviewRequest; -import com.mookive.mookive_backend.review.application.mapper.ReviewMapper; -import com.mookive.mookive_backend.review.domain.entity.Review; -import com.mookive.mookive_backend.review.domain.service.ReviewQueryService; -import com.mookive.mookive_backend.review.domain.service.ReviewSaveService; -import com.mookive.mookive_backend.user.domain.entity.User; -import com.mookive.mookive_backend.user.domain.service.UserQueryService; -import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Optional; - -@Service -@RequiredArgsConstructor -@Transactional -public class ReviewCreateService { - - private final MovieQueryService movieQueryService; - private final UserQueryService userQueryService; - private final ReviewSaveService reviewSaveService; - private final KeywordSaveService keywordSaveService; - private final KeywordDeleteService keywordDeleteService; - private final ReviewQueryService reviewQueryService; - - public void createReview(ReviewRequest.ReviewCreateRequest reviewCreateRequest) { - Long movieId = reviewCreateRequest.getMovieId(); - Long userId = reviewCreateRequest.getUserId(); - Optional optionalReview = reviewQueryService.findByUserIdAndMovieId(userId, movieId); - if(optionalReview.isPresent()){ - Review review = optionalReview.get(); - LocalDate date = reviewCreateRequest.getDate(); - String rating = reviewCreateRequest.getRating(); - String text = reviewCreateRequest.getText(); - ArrayList keywords = reviewCreateRequest.getKeywords(); - review.updateReview(rating, text, date); - keywordDeleteService.deleteAllByReviewId(review.getId()); - saveKeywords(keywords, review, movieId); - } - else { - Movie movie = movieQueryService.findById(movieId); - User user = userQueryService.findById(userId); - Review review = ReviewMapper.mapToReview(reviewCreateRequest, movie, user); - reviewSaveService.saveReview(review); - ArrayList keywords = reviewCreateRequest.getKeywords(); - saveKeywords(keywords, review, movieId); - } - } - - private void saveKeywords(ArrayList keywords, Review review, Long movieId) { - for(String word : keywords){ - Keyword keyword = KeywordMapper.mapToKeyword(review, word, movieId); - keywordSaveService.saveKeyword(keyword); - } - } -} diff --git a/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java b/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java deleted file mode 100644 index f566b46..0000000 --- a/src/main/java/com/mookive/mookive_backend/review/domain/repository/ReviewRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mookive.mookive_backend.review.domain.repository; - -import com.mookive.mookive_backend.review.domain.entity.Review; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface ReviewRepository extends JpaRepository { - - Optional findByUserIdAndMovieId(Long userId, Long movieId);; -} diff --git a/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java b/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java deleted file mode 100644 index cc657a5..0000000 --- a/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewQueryService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.mookive.mookive_backend.review.domain.service; - -import com.mookive.mookive_backend.review.domain.entity.Review; -import com.mookive.mookive_backend.review.domain.repository.ReviewRepository; -import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.Optional; - -@Service -@RequiredArgsConstructor -@Transactional -public class ReviewQueryService { - - private final ReviewRepository reviewRepository; - - public Review findById(Long reviewId) { - return reviewRepository.findById(reviewId) - .orElseThrow(() -> new IllegalArgumentException("Review not found")); - } - - public Optional findByUserIdAndMovieId(Long userId, Long movieId) { - return reviewRepository.findByUserIdAndMovieId(userId, movieId); - } - -} diff --git a/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewSaveService.java b/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewSaveService.java deleted file mode 100644 index 77b585d..0000000 --- a/src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewSaveService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mookive.mookive_backend.review.domain.service; - -import com.mookive.mookive_backend.review.domain.entity.Review; -import com.mookive.mookive_backend.review.domain.repository.ReviewRepository; -import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -@Transactional -public class ReviewSaveService { - - private final ReviewRepository reviewRepository; - - public void saveReview(Review review) { - reviewRepository.save(review); - } -} diff --git a/src/main/java/com/mookive/mookive_backend/review/presentation/ReviewController.java b/src/main/java/com/mookive/mookive_backend/review/presentation/ReviewController.java deleted file mode 100644 index e0a7885..0000000 --- a/src/main/java/com/mookive/mookive_backend/review/presentation/ReviewController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.mookive.mookive_backend.review.presentation; - -import com.mookive.mookive_backend.review.application.dto.request.ReviewRequest; -import com.mookive.mookive_backend.review.application.dto.response.ReviewResponse; -import com.mookive.mookive_backend.review.application.service.ReviewCreateService; -import com.mookive.mookive_backend.review.application.service.ReviewGetService; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequiredArgsConstructor -public class ReviewController { - - private final ReviewCreateService reviewCreateService; - private final ReviewGetService reviewGetService; - - @PostMapping("/review") - public void createReview(@RequestBody ReviewRequest.ReviewCreateRequest reviewCreateRequest) { - reviewCreateService.createReview(reviewCreateRequest); - } - - @GetMapping("/review/{reviewId}") - public ReviewResponse.ReviewDetailResponse getReview(@PathVariable Long reviewId) { - return reviewGetService.getReview(reviewId); - } - -} From a570f7758248b88ba6596537c651823ebabb1650 Mon Sep 17 00:00:00 2001 From: syyling Date: Thu, 4 Apr 2024 14:37:55 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[refactor]=20Record=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20text=EC=97=90=EC=84=9C=20review=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record/application/dto/request/RecordRequest.java | 6 +++--- .../application/dto/response/RecordResponse.java | 6 +++--- .../record/application/mapper/RecordMapper.java | 4 ++-- .../application/service/RecordCreateService.java | 6 ++---- .../mookive_backend/record/domain/entity/Record.java | 10 +++++----- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java b/src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java index 3200a00..3dfe6af 100644 --- a/src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/dto/request/RecordRequest.java @@ -15,18 +15,18 @@ public static class RecordCreateRequest { private Long movieId; private Long userId; private String rating; - private String text; + private String review; private LocalDate date; private ArrayList keywords; @Builder public RecordCreateRequest(Long movieId, Long userId, String rating, - String text, LocalDate date, ArrayList keywords) { + String review, LocalDate date, ArrayList keywords) { this.movieId = movieId; this.userId = userId; this.rating = rating; - this.text = text; + this.review = review; this.date = date; this.keywords = keywords; } diff --git a/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java b/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java index 12af934..3b3661c 100644 --- a/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java @@ -13,14 +13,14 @@ public class RecordResponse { @NoArgsConstructor public static class RecordDetailResponse{ private String rating; - private String text; + private String review; private LocalDate date; private List keywords; @Builder - public RecordDetailResponse(String rating, String text, LocalDate date, List keywords) { + public RecordDetailResponse(String rating, String review, LocalDate date, List keywords) { this.rating = rating; - this.text = text; + this.review = review; this.date = date; this.keywords = keywords; } diff --git a/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java b/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java index 1e14947..5f1d1f8 100644 --- a/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.java @@ -15,7 +15,7 @@ public static Record mapToRecord(RecordRequest.RecordCreateRequest recordCreateR .movie(movie) .user(user) .rating(recordCreateRequest.getRating()) - .text(recordCreateRequest.getText()) + .review(recordCreateRequest.getReview()) .date(recordCreateRequest.getDate()) .build(); } @@ -23,7 +23,7 @@ public static Record mapToRecord(RecordRequest.RecordCreateRequest recordCreateR public static RecordResponse.RecordDetailResponse mapToRecordDetailResponse(Record record, List keywords) { return RecordResponse.RecordDetailResponse.builder() .rating(record.getRating()) - .text(record.getText()) + .review(record.getReview()) .date(record.getDate()) .keywords(keywords) .build(); diff --git a/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java b/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java index 6c61e21..12d59ff 100644 --- a/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.java @@ -10,8 +10,6 @@ import com.mookive.mookive_backend.record.application.dto.request.RecordRequest; import com.mookive.mookive_backend.record.application.mapper.RecordMapper; import com.mookive.mookive_backend.record.domain.entity.Record; -import com.mookive.mookive_backend.record.domain.entity.Record; -import com.mookive.mookive_backend.record.domain.service.RecordQueryService; import com.mookive.mookive_backend.record.domain.service.RecordQueryService; import com.mookive.mookive_backend.record.domain.service.RecordSaveService; import com.mookive.mookive_backend.user.domain.entity.User; @@ -44,9 +42,9 @@ public void createRecord(RecordRequest.RecordCreateRequest recordCreateRequest) Record record = optionalRecord.get(); LocalDate date = recordCreateRequest.getDate(); String rating = recordCreateRequest.getRating(); - String text = recordCreateRequest.getText(); + String review = recordCreateRequest.getReview(); ArrayList keywords = recordCreateRequest.getKeywords(); - record.updateRecord(rating, text, date); + record.updateRecord(rating, review, date); keywordDeleteService.deleteAllByRecordId(record.getId()); saveKeywords(keywords, record, movieId); } diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java b/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java index e235543..a23dd8f 100644 --- a/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java +++ b/src/main/java/com/mookive/mookive_backend/record/domain/entity/Record.java @@ -20,7 +20,7 @@ public class Record { private Long id; private String rating; - private String text; + private String review; private LocalDate date; @ManyToOne @@ -32,17 +32,17 @@ public class Record { private Movie movie; @Builder - public Record(String rating, String text, LocalDate date, User user, Movie movie) { + public Record(String rating, String review, LocalDate date, User user, Movie movie) { this.rating = rating; - this.text = text; + this.review = review; this.date = date; this.user = user; this.movie = movie; } - public void updateRecord(String rating, String text, LocalDate date) { + public void updateRecord(String rating, String review, LocalDate date) { this.rating = rating; - this.text = text; + this.review = review; this.date = date; } }