-
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
169 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/com/mookive/mookive_backend/keyword/application/mapper/KeywordMapper.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,14 @@ | ||
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; | ||
|
||
public class KeywordMapper { | ||
|
||
public static Keyword mapToKeyword(Review review, String word) { | ||
return Keyword.builder() | ||
.review(review) | ||
.word(word) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/mookive/mookive_backend/keyword/domain/service/KeywordSaveService.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,17 @@ | ||
package com.mookive.mookive_backend.keyword.domain.service; | ||
|
||
import com.mookive.mookive_backend.keyword.domain.entity.Keyword; | ||
import com.mookive.mookive_backend.keyword.domain.repository.KeywordRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class KeywordSaveService { | ||
|
||
private final KeywordRepository keywordRepository; | ||
|
||
public void saveKeyword(Keyword keyword) { | ||
keywordRepository.save(keyword); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/mookive/mookive_backend/review/application/dto/request/ReviewRequest.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,34 @@ | ||
package com.mookive.mookive_backend.review.application.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
|
||
public class ReviewRequest { | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class ReviewCreateRequest { | ||
private Long movieId; | ||
private Long userId; | ||
private String rating; | ||
private String text; | ||
private LocalDate date; | ||
private ArrayList<String> keywords; | ||
|
||
|
||
@Builder | ||
public ReviewCreateRequest(Long movieId, Long userId, String rating, | ||
String text, LocalDate date, ArrayList<String> keywords) { | ||
this.movieId = movieId; | ||
this.userId = userId; | ||
this.rating = rating; | ||
this.text = text; | ||
this.date = date; | ||
this.keywords = keywords; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mookive/mookive_backend/review/application/mapper/ReviewMapper.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.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.domain.entity.Review; | ||
import com.mookive.mookive_backend.user.domain.entity.User; | ||
|
||
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(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...main/java/com/mookive/mookive_backend/review/application/service/ReviewCreateService.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,43 @@ | ||
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.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.ReviewSaveService; | ||
import com.mookive.mookive_backend.user.domain.entity.User; | ||
import com.mookive.mookive_backend.user.domain.service.UserQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewCreateService { | ||
|
||
private final MovieQueryService movieQueryService; | ||
private final UserQueryService userQueryService; | ||
private final ReviewSaveService reviewSaveService; | ||
private final KeywordSaveService keywordSaveService; | ||
|
||
public void createReview(ReviewRequest.ReviewCreateRequest reviewCreateRequest) { | ||
Long movieId = reviewCreateRequest.getMovieId(); | ||
Movie movie = movieQueryService.findById(movieId); | ||
Long userId = reviewCreateRequest.getUserId(); | ||
User user = userQueryService.findById(userId); | ||
Review review = ReviewMapper.mapToReview(reviewCreateRequest, movie, user); | ||
reviewSaveService.saveReview(review); | ||
|
||
ArrayList<String> keywords = reviewCreateRequest.getKeywords(); | ||
for(String word : keywords){ | ||
Keyword keyword = KeywordMapper.mapToKeyword(review, word); | ||
keywordSaveService.saveKeyword(keyword); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/mookive/mookive_backend/review/domain/service/ReviewSaveService.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,17 @@ | ||
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 lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewSaveService { | ||
|
||
private final ReviewRepository reviewRepository; | ||
|
||
public void saveReview(Review review) { | ||
reviewRepository.save(review); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mookive/mookive_backend/review/presentation/ReviewController.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.review.presentation; | ||
|
||
import com.mookive.mookive_backend.review.application.dto.request.ReviewRequest; | ||
import com.mookive.mookive_backend.review.application.service.ReviewCreateService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ReviewController { | ||
|
||
private final ReviewCreateService reviewCreateService; | ||
|
||
@PostMapping("/review") | ||
public void createReview(@RequestBody ReviewRequest.ReviewCreateRequest reviewCreateRequest) { | ||
reviewCreateService.createReview(reviewCreateRequest); | ||
} | ||
} |