Skip to content

Commit

Permalink
Merge pull request #23 from syyling/feat/18
Browse files Browse the repository at this point in the history
[feat] movie 테이블 tagline 필드 추가, Review 테이블명 Record로 변경
  • Loading branch information
syyling authored Apr 4, 2024
2 parents c4c10c2 + a570f77 commit 10f12ab
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 237 deletions.
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public interface KeywordRepository extends JpaRepository<Keyword, Long> {

List<Keyword> findByReviewId(Long reviewId);
List<Keyword> findByRecordId(Long recordId);

void deleteAllByReviewId(Long reviewId);
void deleteAllByRecordId(Long recordId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class KeywordQueryService {

private final KeywordRepository keywordRepository;

public List<Keyword> findByReviewId(Long reviewId) {
return keywordRepository.findByReviewId(reviewId);
public List<Keyword> findByRecordId(Long recordId) {
return keywordRepository.findByRecordId(recordId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ 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;
this.year = year;
this.plot = plot;
this.poster = poster;
this.nation = nation;
this.tagline = tagline;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static MovieResponse.MovieDetailResponse mapToMovieDetailResponse(Movie m
.plot(movie.getPlot())
.nation(movie.getNation())
.poster(movie.getPoster())
.tagline(movie.getTagline())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Movie searchMovie(String tmdbId) {
.poster(tmdbResponse.getPoster())
.nation(koficResponse.getNation())
.director(koficResponse.getDirector())
.tagline(tmdbResponse.getTagline())
.build();
}

Expand All @@ -46,13 +47,15 @@ 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())
.year(year.toString())
.genre(genre.toString())
.plot(plot.toString())
.poster(poster.toString())
.tagline(tagline.toString())
.build();
}

Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPlayList(Long playlistId) {
Playlist playlist = playlistQueryService.findById(playlistId);
Expand All @@ -33,10 +33,10 @@ public List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> getMovieInPl
List<MovieInPlaylistResponse.MovieInPlaylistDefaultResponse> movieInPlaylistDefaultResponseList = movieInPlaylistList.stream().map(movieInPlaylist ->
{
Long movieId = movieInPlaylist.getMovie().getId();
Optional<Review> review = reviewQueryService.findByUserIdAndMovieId(userId, movieId);
Optional<Record> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -7,26 +7,26 @@
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;
private String text;
private String review;
private LocalDate date;
private ArrayList<String> keywords;


@Builder
public ReviewCreateRequest(Long movieId, Long userId, String rating,
String text, LocalDate date, ArrayList<String> keywords) {
public RecordCreateRequest(Long movieId, Long userId, String rating,
String review, LocalDate date, ArrayList<String> keywords) {
this.movieId = movieId;
this.userId = userId;
this.rating = rating;
this.text = text;
this.review = review;
this.date = date;
this.keywords = keywords;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -7,20 +7,20 @@
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 String review;
private LocalDate date;
private List<String> keywords;

@Builder
public ReviewDetailResponse(String rating, String text, LocalDate date, List<String> keywords) {
public RecordDetailResponse(String rating, String review, LocalDate date, List<String> keywords) {
this.rating = rating;
this.text = text;
this.review = review;
this.date = date;
this.keywords = keywords;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
.review(recordCreateRequest.getReview())
.date(recordCreateRequest.getDate())
.build();
}

public static RecordResponse.RecordDetailResponse mapToRecordDetailResponse(Record record, List<String> keywords) {
return RecordResponse.RecordDetailResponse.builder()
.rating(record.getRating())
.review(record.getReview())
.date(record.getDate())
.keywords(keywords)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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.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<Record> optionalRecord = recordQueryService.findByUserIdAndMovieId(userId, movieId);
if(optionalRecord.isPresent()){
Record record = optionalRecord.get();
LocalDate date = recordCreateRequest.getDate();
String rating = recordCreateRequest.getRating();
String review = recordCreateRequest.getReview();
ArrayList<String> keywords = recordCreateRequest.getKeywords();
record.updateRecord(rating, review, 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<String> keywords = recordCreateRequest.getKeywords();
saveKeywords(keywords, record, movieId);
}
}

private void saveKeywords(ArrayList<String> keywords, Record record, Long movieId) {
for(String word : keywords){
Keyword keyword = KeywordMapper.mapToKeyword(record, word, movieId);
keywordSaveService.saveKeyword(keyword);
}
}
}
Loading

0 comments on commit 10f12ab

Please sign in to comment.