1차 팀프로젝트 13회차

이동원·2024년 7월 1일

Review 보여주기

  @GetMapping
    public ResponseEntity<?> getReview(@RequestHeader("ProductId") Long productId) {
        List<ReviewResponseDTO> reviewResponseDTOList = multiService.getReview(productId);
        return ResponseEntity.status(HttpStatus.OK).body(reviewResponseDTOList);
    }
 public List<ReviewResponseDTO> getReview(Long productId) {
        //product id 가지고 List<ReviewResponseDTO> 로 보내줘야함
        Product product = productService.getProduct(productId);
        List<Review> reviewList = reviewService.getList(product);

        List<ReviewResponseDTO> reviewResponseDTOList = new ArrayList<>();
        for (Review review : reviewList) {
            reviewResponseDTOList.add(ReviewResponseDTO.builder()
                    .review(review)
                    .modifyDate(this.dateTimeTransfer(review.getModifyDate()))
                    .createDate(this.dateTimeTransfer(review.getCreateDate()))
                    .build());


        }
        return reviewResponseDTOList;
    }
  public List<Review> getList(Product product) {

        return this.reviewRepository.findByProductOrderByCreateDateDesc(product);
    }

0개의 댓글