Skip to content

Commit

Permalink
[feat] 리뷰 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
syyling committed Mar 11, 2024
1 parent 01fc20a commit b974f63
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import com.mookive.mookive_backend.keyword.domain.entity.Keyword;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface KeywordRepository extends JpaRepository<Keyword, Long> {

List<Keyword> findByReviewId(Long reviewId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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;

import java.util.List;

@Service
@RequiredArgsConstructor
public class KeywordQueryService {

private final KeywordRepository keywordRepository;

public List<Keyword> findByReviewId(Long reviewId) {
return keywordRepository.findByReviewId(reviewId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mookive.mookive_backend.review.application.dto.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.List;

public class ReviewResponse {

@Getter
@NoArgsConstructor
public static class ReviewDetailResponse {
private String rating;
private String text;
private LocalDate date;
private List<String> keywords;

@Builder
public ReviewDetailResponse(String rating, String text, LocalDate date, List<String> keywords) {
this.rating = rating;
this.text = text;
this.date = date;
this.keywords = keywords;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

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) {
Expand All @@ -16,4 +19,13 @@ public static Review mapToReview(ReviewRequest.ReviewCreateRequest reviewCreateR
.date(reviewCreateRequest.getDate())
.build();
}

public static ReviewResponse.ReviewDetailResponse mapToReviewDetailResponse(Review review, List<String> keywords) {
return ReviewResponse.ReviewDetailResponse.builder()
.rating(review.getRating())
.text(review.getText())
.date(review.getDate())
.keywords(keywords)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mookive.mookive_backend.review.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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ReviewGetService {

private final ReviewQueryService reviewQueryService;
private final KeywordQueryService keywordQueryService;

public ReviewResponse.ReviewDetailResponse getReview(Long reviewId) {
Review review = reviewQueryService.findById(reviewId);
List<Keyword> keywordList = keywordQueryService.findByReviewId(reviewId);
List<String> keywords= new ArrayList<>();
for(Keyword keyword : keywordList){
keywords.add(keyword.getWord());
}
return ReviewMapper.mapToReviewDetailResponse(review, keywords);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 ReviewQueryService {

private final ReviewRepository reviewRepository;

public Review findById(Long reviewId) {
return reviewRepository.findById(reviewId)
.orElseThrow(() -> new IllegalArgumentException("Review not found"));
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
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);
}

}

0 comments on commit b974f63

Please sign in to comment.