diff --git a/src/main/java/com/helpmeCookies/review/controller/ReviewController.java b/src/main/java/com/helpmeCookies/review/controller/ReviewController.java index d225e1f..9987947 100644 --- a/src/main/java/com/helpmeCookies/review/controller/ReviewController.java +++ b/src/main/java/com/helpmeCookies/review/controller/ReviewController.java @@ -1,9 +1,12 @@ package com.helpmeCookies.review.controller; import com.helpmeCookies.review.dto.ReviewRequest; +import com.helpmeCookies.review.dto.ReviewResponse; +import com.helpmeCookies.review.entity.Review; import com.helpmeCookies.review.service.ReviewService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -33,4 +36,10 @@ public ResponseEntity editReview(@RequestBody ReviewRequest request, @Path reviewService.editReview(request, productId, reviewId); return ResponseEntity.ok().build(); } + + @GetMapping("/{reviewId}") + public ResponseEntity getReview(@PathVariable Long reviewId) { + Review response = reviewService.getReview(reviewId); + return ResponseEntity.ok(ReviewResponse.fromEntity(response)); + } } diff --git a/src/main/java/com/helpmeCookies/review/dto/ReviewResponse.java b/src/main/java/com/helpmeCookies/review/dto/ReviewResponse.java new file mode 100644 index 0000000..044f00f --- /dev/null +++ b/src/main/java/com/helpmeCookies/review/dto/ReviewResponse.java @@ -0,0 +1,11 @@ +package com.helpmeCookies.review.dto; + +import com.helpmeCookies.product.entity.Product; +import com.helpmeCookies.review.entity.Review; +import com.helpmeCookies.user.entity.User; + +public record ReviewResponse(Long id, String content,User writer, Product product) { + public static ReviewResponse fromEntity(Review review) { + return new ReviewResponse(review.getId(), review.getContent(),review.getWriter(), review.getProduct()); + } +} diff --git a/src/main/java/com/helpmeCookies/review/entity/Review.java b/src/main/java/com/helpmeCookies/review/entity/Review.java index da4f5d8..1c9af76 100644 --- a/src/main/java/com/helpmeCookies/review/entity/Review.java +++ b/src/main/java/com/helpmeCookies/review/entity/Review.java @@ -43,4 +43,20 @@ public Review() {} public void updateContent(String content) { this.content = content; } + + public Long getId() { + return id; + } + + public String getContent() { + return content; + } + + public User getWriter() { + return writer; + } + + public Product getProduct() { + return product; + } } diff --git a/src/main/java/com/helpmeCookies/review/service/ReviewService.java b/src/main/java/com/helpmeCookies/review/service/ReviewService.java index 4cf9c0e..a7f873a 100644 --- a/src/main/java/com/helpmeCookies/review/service/ReviewService.java +++ b/src/main/java/com/helpmeCookies/review/service/ReviewService.java @@ -28,4 +28,8 @@ public void editReview(ReviewRequest request, Long productId, Long reviewId) { Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 reviewId 입니다.")); review.updateContent(request.content()); } + + public Review getReview(Long reviewId) { + return reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 reviewId 입니다.")); + } }