Skip to content

Commit

Permalink
fix : [#62] 감상평 수정 기능
Browse files Browse the repository at this point in the history
감상평은 content만 수정 가능
  • Loading branch information
jupyter471 committed Oct 24, 2024
1 parent 2b89c6b commit 6aa7250
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,14 +18,19 @@ public class ReviewController {

private final ReviewService reviewService;

//TODO 감상평 수정
//TODO 감상평 삭제
//TODO 해당 상품의 감상평 조회
//TODO 내 감상평 조회

@PostMapping("/{productId}")
public ResponseEntity<Void> postReview(@RequestBody ReviewRequest request, @PathVariable Long productId) {
reviewService.saveReview(request,productId);
reviewService.saveReview(request, productId);
return ResponseEntity.ok().build();
}

@PutMapping("/{productId}/{reviewId}")
public ResponseEntity<Void> editReview(@RequestBody ReviewRequest request, @PathVariable Long productId, @PathVariable Long reviewId) {
reviewService.editReview(request, productId, reviewId);
return ResponseEntity.ok().build();
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/helpmeCookies/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public Review(Long id, String content, User writer, Product product) {
}

public Review() {}

public void updateContent(String content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.helpmeCookies.product.entity.Product;
import com.helpmeCookies.product.repository.ProductRepository;
import com.helpmeCookies.review.dto.ReviewRequest;
import com.helpmeCookies.review.entity.Review;
import com.helpmeCookies.review.repository.ReviewRepository;
import com.helpmeCookies.user.entity.User;
import com.helpmeCookies.user.repository.UserRepository;
Expand All @@ -22,4 +23,9 @@ public void saveReview(ReviewRequest request, Long productId) {

reviewRepository.save(request.toEntity(writer,product));
}

public void editReview(ReviewRequest request, Long productId, Long reviewId) {
Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("유효하지 않은 reviewId 입니다."));
review.updateContent(request.content());
}
}

0 comments on commit 6aa7250

Please sign in to comment.