Skip to content

Commit

Permalink
feat : [#62] 감상평 조회 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyter471 committed Nov 1, 2024
1 parent f38dd44 commit b3ed71b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,4 +36,10 @@ public ResponseEntity<Void> editReview(@RequestBody ReviewRequest request, @Path
reviewService.editReview(request, productId, reviewId);
return ResponseEntity.ok().build();
}

@GetMapping("/{reviewId}")
public ResponseEntity<ReviewResponse> getReview(@PathVariable Long reviewId) {
Review response = reviewService.getReview(reviewId);
return ResponseEntity.ok(ReviewResponse.fromEntity(response));
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/helpmeCookies/review/dto/ReviewResponse.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/helpmeCookies/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 입니다."));
}
}

0 comments on commit b3ed71b

Please sign in to comment.