From 8272147217642fed33e02f12df35272c0b1b0d2d Mon Sep 17 00:00:00 2001 From: JiinHong Date: Mon, 21 Oct 2024 19:28:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=A1=B0=ED=9A=8C=20API=20(=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=20=EA=B8=B0=EC=88=A0=20=EC=A0=81=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...onseDto.java => ReviewGetResponseDto.java} | 2 +- .../domain/port/review/ReviewGetAllPort.java | 12 +++ .../port/review/ReviewGetRecentPort.java | 4 +- .../domain/service/review/ReviewService.java | 11 ++- .../usecase/review/ReviewGetAllUseCase.java | 12 +++ .../review/ReviewGetRecentUseCase.java | 4 +- .../review/presentation/ReviewController.java | 17 ++++- .../presentation/ReviewControllerDocs.java | 21 +++++- .../review/adapter/ReviewGetAllAdapter.java | 74 +++++++++++++++++++ .../adapter/ReviewGetRecentAdapter.java | 6 +- .../repository/review/ReviewRepository.java | 3 + 11 files changed, 153 insertions(+), 13 deletions(-) rename domain/src/main/java/com/pocket/domain/dto/review/{ReviewGetRecentResponseDto.java => ReviewGetResponseDto.java} (76%) create mode 100644 domain/src/main/java/com/pocket/domain/port/review/ReviewGetAllPort.java create mode 100644 domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetAllUseCase.java create mode 100644 outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java diff --git a/domain/src/main/java/com/pocket/domain/dto/review/ReviewGetRecentResponseDto.java b/domain/src/main/java/com/pocket/domain/dto/review/ReviewGetResponseDto.java similarity index 76% rename from domain/src/main/java/com/pocket/domain/dto/review/ReviewGetRecentResponseDto.java rename to domain/src/main/java/com/pocket/domain/dto/review/ReviewGetResponseDto.java index bf0ec80..dad6032 100644 --- a/domain/src/main/java/com/pocket/domain/dto/review/ReviewGetRecentResponseDto.java +++ b/domain/src/main/java/com/pocket/domain/dto/review/ReviewGetResponseDto.java @@ -2,7 +2,7 @@ import java.util.List; -public record ReviewGetRecentResponseDto( +public record ReviewGetResponseDto( int reviewCount, List reviews ) { diff --git a/domain/src/main/java/com/pocket/domain/port/review/ReviewGetAllPort.java b/domain/src/main/java/com/pocket/domain/port/review/ReviewGetAllPort.java new file mode 100644 index 0000000..e371b36 --- /dev/null +++ b/domain/src/main/java/com/pocket/domain/port/review/ReviewGetAllPort.java @@ -0,0 +1,12 @@ +package com.pocket.domain.port.review; + +import com.pocket.domain.dto.review.ReviewGetResponseDto; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface ReviewGetAllPort { + + ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable); + +} diff --git a/domain/src/main/java/com/pocket/domain/port/review/ReviewGetRecentPort.java b/domain/src/main/java/com/pocket/domain/port/review/ReviewGetRecentPort.java index 68d797b..2c033cc 100644 --- a/domain/src/main/java/com/pocket/domain/port/review/ReviewGetRecentPort.java +++ b/domain/src/main/java/com/pocket/domain/port/review/ReviewGetRecentPort.java @@ -1,9 +1,9 @@ package com.pocket.domain.port.review; -import com.pocket.domain.dto.review.ReviewGetRecentResponseDto; +import com.pocket.domain.dto.review.ReviewGetResponseDto; public interface ReviewGetRecentPort { - ReviewGetRecentResponseDto getRecentReview(Long photoboothId); + ReviewGetResponseDto getRecentReview(Long photoboothId); } diff --git a/domain/src/main/java/com/pocket/domain/service/review/ReviewService.java b/domain/src/main/java/com/pocket/domain/service/review/ReviewService.java index 7ff0d16..3848af0 100644 --- a/domain/src/main/java/com/pocket/domain/service/review/ReviewService.java +++ b/domain/src/main/java/com/pocket/domain/service/review/ReviewService.java @@ -6,12 +6,13 @@ import com.pocket.domain.port.review.*; import com.pocket.domain.usecase.review.*; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; import java.util.List; @DomainService @RequiredArgsConstructor -public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUseCase, ReviewGetRecentUseCase, ReviewGetAllImagesUseCase, ReviewBoothFeatureCountUseCase, ReviewPhotoFeatureCountUseCase, ReviewGetBoothFeatureUseCase, ReviewGetPhotoFeatureUseCase +public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUseCase, ReviewGetRecentUseCase, ReviewGetAllImagesUseCase, ReviewBoothFeatureCountUseCase, ReviewPhotoFeatureCountUseCase, ReviewGetBoothFeatureUseCase, ReviewGetPhotoFeatureUseCase, ReviewGetAllUseCase { @@ -23,6 +24,7 @@ public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUse private final ReviewPhotoFeatureCountPort reviewPhotoFeatureCountPort; private final ReviewGetBoothFeaturePort reviewGetBoothFeaturePort; private final ReviewGetPhotoFeaturePort reviewGetPhotoFeaturePort; + private final ReviewGetAllPort reviewGetAllPort; @Override public ReviewRegisterResponseDto registerReviewResponse(ReviewRegisterRequestDto reviewRegisterRequestDto, String name) { @@ -35,7 +37,7 @@ public ReviewGet6ImagesResponseDto get6Images(Long photoboothId) { } @Override - public ReviewGetRecentResponseDto getRecentReview(Long photoboothId) { + public ReviewGetResponseDto getRecentReview(Long photoboothId) { return reviewGetRecentPort.getRecentReview(photoboothId); } @@ -63,4 +65,9 @@ public List getBoothFeatures() { public List getPhotoFeatures() { return reviewGetPhotoFeaturePort.getPhotoFeatures(); } + + @Override + public ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable) { + return reviewGetAllPort.getAllReviews(photoboothId, pageable); + } } diff --git a/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetAllUseCase.java b/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetAllUseCase.java new file mode 100644 index 0000000..47999fb --- /dev/null +++ b/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetAllUseCase.java @@ -0,0 +1,12 @@ +package com.pocket.domain.usecase.review; + +import com.pocket.domain.dto.review.ReviewGetResponseDto; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface ReviewGetAllUseCase { + + ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable); + +} diff --git a/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetRecentUseCase.java b/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetRecentUseCase.java index 6d0d2ce..e09055b 100644 --- a/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetRecentUseCase.java +++ b/domain/src/main/java/com/pocket/domain/usecase/review/ReviewGetRecentUseCase.java @@ -1,10 +1,10 @@ package com.pocket.domain.usecase.review; -import com.pocket.domain.dto.review.ReviewGetRecentResponseDto; +import com.pocket.domain.dto.review.ReviewGetResponseDto; public interface ReviewGetRecentUseCase { - ReviewGetRecentResponseDto getRecentReview(Long photoboohtId); + ReviewGetResponseDto getRecentReview(Long photoboohtId); } diff --git a/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewController.java b/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewController.java index 2aab302..abcbc35 100644 --- a/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewController.java +++ b/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewController.java @@ -5,6 +5,8 @@ import com.pocket.domain.dto.user.UserInfoDTO; import com.pocket.domain.usecase.review.*; import lombok.RequiredArgsConstructor; +import org.springdoc.core.annotations.ParameterObject; +import org.springframework.data.domain.Pageable; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -23,6 +25,7 @@ public class ReviewController implements ReviewControllerDocs { private final ReviewPhotoFeatureCountUseCase reviewPhotoFeatureCountUseCase; private final ReviewGetBoothFeatureUseCase reviewGetBoothFeatureUseCase; private final ReviewGetPhotoFeatureUseCase reviewGetPhotoFeatureUseCase; + private final ReviewGetAllUseCase reviewGetAllUseCase; @PostMapping public ApplicationResponse postReview( @@ -44,6 +47,7 @@ public ApplicationResponse> getAllPhotoFeature() { return ApplicationResponse.ok(response); } + @GetMapping("/images/{photobooth_id}") public ApplicationResponse getReviewHomeImage( @PathVariable("photobooth_id") Long photoboothId @@ -53,10 +57,10 @@ public ApplicationResponse getReviewHomeImage( } @GetMapping("/reviews/{photobooth_id}") - public ApplicationResponse getRecentReview( + public ApplicationResponse getRecentReview( @PathVariable("photobooth_id") Long photoboothId ) { - ReviewGetRecentResponseDto response = reviewGetRecentUseCase.getRecentReview(photoboothId); + ReviewGetResponseDto response = reviewGetRecentUseCase.getRecentReview(photoboothId); return ApplicationResponse.ok(response); } @@ -84,4 +88,13 @@ public ApplicationResponse> getReviewPhotoFeatures( return ApplicationResponse.ok(response); } + @GetMapping("/allreviews/{photobooth_id}") + public ApplicationResponse getAllReviews( + @PathVariable("photobooth_id") Long photoboothId, + @ParameterObject final Pageable pageable + ) { + ReviewGetResponseDto response = reviewGetAllUseCase.getAllReviews(photoboothId, pageable); + return ApplicationResponse.ok(response); + } + } diff --git a/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewControllerDocs.java b/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewControllerDocs.java index ba3eb13..2975dca 100644 --- a/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewControllerDocs.java +++ b/inbounds/src/main/java/com/pocket/inbounds/review/presentation/ReviewControllerDocs.java @@ -5,11 +5,14 @@ import com.pocket.domain.dto.review.*; import com.pocket.domain.dto.user.UserInfoDTO; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springdoc.core.annotations.ParameterObject; +import org.springframework.data.domain.Pageable; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -52,7 +55,7 @@ ApplicationResponse getReviewHomeImage( content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}) }) @Operation(summary = "최신 리뷰 조회", description = "특정 포토부스에 대한 최신 리뷰를 조회하는 API") - ApplicationResponse getRecentReview( + ApplicationResponse getRecentReview( @PathVariable("photobooth_id") Long photoboothId ); @@ -111,4 +114,20 @@ ApplicationResponse> getReviewPhotoFeatures( }) @Operation(summary = "포토부스의 모든 사진 특징 조회", description = "포토부스에서 찍힌 모든 사진의 특징을 가져오는 API") ApplicationResponse> getAllPhotoFeature(); + + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "BAD REQUEST", + content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}), + @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR", + content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}) + }) + @Operation(summary = "전체 리뷰 조회", description = "페이징을 이용한 전체 리뷰 조회 API (ex. /api/v1/review/allreviews/336?page=0&size=10&sort=id,desc)") + ApplicationResponse getAllReviews( + @Parameter(description = "포토부스 ID", example = "336") + @PathVariable("photobooth_id") Long photoboothId, + + @ParameterObject Pageable pageable + ); + } diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java new file mode 100644 index 0000000..3cc714f --- /dev/null +++ b/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java @@ -0,0 +1,74 @@ +package com.pocket.outbound.adapter.review.adapter; + + +import com.pocket.core.aop.annotation.AdapterService; +import com.pocket.core.exception.review.ReviewCustomException; +import com.pocket.core.exception.review.ReviewErrorCode; +import com.pocket.domain.dto.review.ReviewGetResponseDto; +import com.pocket.domain.dto.review.ReviewPreviewDto; +import com.pocket.domain.port.review.ReviewGetAllPort; +import com.pocket.outbound.adapter.review.mapper.ReviewOutBoundMapper; +import com.pocket.outbound.entity.review.JpaBoothFeature; +import com.pocket.outbound.entity.review.JpaPhotoFeature; +import com.pocket.outbound.entity.review.JpaReview; +import com.pocket.outbound.entity.review.JpaReviewImage; +import com.pocket.outbound.repository.review.*; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@AdapterService +@RequiredArgsConstructor +public class ReviewGetAllAdapter implements ReviewGetAllPort { + + private final ReviewRepository reviewRepository; + private final ReviewImageRepository reviewImageRepository; + private final ReviewBoothFeatureRepository reviewBoothFeatureRepository; + private final ReviewPhotoFeatureRepository reviewPhotoFeatureRepository; + private final BoothFeatureRepository boothFeatureRepository; + private final PhotoFeatureRepository photoFeatureRepository; + private final ReviewOutBoundMapper reviewOutBoundMapper; + + @Override + public ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable) { + int totalReviewCount = reviewRepository.countByPhotoBoothId(photoboothId); + + Page reviews = reviewRepository.findByPhotoBoothId(photoboothId, pageable); + + List reviewPreviews = reviews.stream().map(review -> { + List images = reviewImageRepository.findByReviewId(review.getId()); + String imageUrl = images.isEmpty() ? "" : images.get(0).getImage().getImageUrl(); + int imageCount = images.size(); + + + // Booth Features 찾기 + List boothFeatureIds = reviewBoothFeatureRepository.findBoothFeatureIdByReviewId(review.getId()); + List boothFeatures = boothFeatureIds.stream() + .map(boothFeatureId -> boothFeatureRepository.findById(boothFeatureId) + .orElseThrow(() -> new ReviewCustomException(ReviewErrorCode.BOOTH_FEATURE_NOT_FOUND))) + .toList(); + + // Photo Features 찾기 + List photoFeatureIds = reviewPhotoFeatureRepository.findPhotoFeatureIdByReviewId(review.getId()); + List photoFeatures = photoFeatureIds.stream() + .map(photoFeatureId -> photoFeatureRepository.findById(photoFeatureId) + .orElseThrow(() -> new ReviewCustomException(ReviewErrorCode.PHOTO_FEATURE_NOT_FOUND))) + .toList(); + + List descriptions = new ArrayList<>(); + // BoothFeature descriptions + boothFeatures.forEach(boothFeature -> descriptions.add(boothFeature.getBoothFeature().getDescription())); + // PhotoFeature descriptions + photoFeatures.forEach(photoFeature -> descriptions.add(photoFeature.getPhotoFeature().getDescription())); + + return reviewOutBoundMapper.toReviewPreviewDto(descriptions, review, imageUrl, imageCount); + }).collect(Collectors.toList()); + + return new ReviewGetResponseDto(totalReviewCount, reviewPreviews); + } + +} diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetRecentAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetRecentAdapter.java index 062fed8..2a62a72 100644 --- a/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetRecentAdapter.java +++ b/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetRecentAdapter.java @@ -4,7 +4,7 @@ import com.pocket.core.aop.annotation.AdapterService; import com.pocket.core.exception.review.ReviewCustomException; import com.pocket.core.exception.review.ReviewErrorCode; -import com.pocket.domain.dto.review.ReviewGetRecentResponseDto; +import com.pocket.domain.dto.review.ReviewGetResponseDto; import com.pocket.domain.dto.review.ReviewPreviewDto; import com.pocket.domain.port.review.ReviewGetRecentPort; import com.pocket.outbound.adapter.review.mapper.ReviewOutBoundMapper; @@ -32,7 +32,7 @@ public class ReviewGetRecentAdapter implements ReviewGetRecentPort { private final ReviewOutBoundMapper reviewOutBoundMapper; @Override - public ReviewGetRecentResponseDto getRecentReview(Long photoboothId) { + public ReviewGetResponseDto getRecentReview(Long photoboothId) { int totalReviewCount = reviewRepository.countByPhotoBoothId(photoboothId); List recentReviews = reviewRepository.findTop2ByPhotoBoothIdOrderByIdDesc(photoboothId); @@ -67,6 +67,6 @@ public ReviewGetRecentResponseDto getRecentReview(Long photoboothId) { return reviewOutBoundMapper.toReviewPreviewDto(descriptions, review, imageUrl, imageCount); }).collect(Collectors.toList()); - return new ReviewGetRecentResponseDto(totalReviewCount, reviewPreviews); + return new ReviewGetResponseDto(totalReviewCount, reviewPreviews); } } diff --git a/outbound/src/main/java/com/pocket/outbound/repository/review/ReviewRepository.java b/outbound/src/main/java/com/pocket/outbound/repository/review/ReviewRepository.java index 2789228..2148b32 100644 --- a/outbound/src/main/java/com/pocket/outbound/repository/review/ReviewRepository.java +++ b/outbound/src/main/java/com/pocket/outbound/repository/review/ReviewRepository.java @@ -1,6 +1,8 @@ package com.pocket.outbound.repository.review; import com.pocket.outbound.entity.review.JpaReview; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -17,4 +19,5 @@ public interface ReviewRepository extends JpaRepository { @Query("SELECT r.id FROM JpaReview r WHERE r.photoBooth.id = :photoBoothId") List findReviewIdsByPhotoBoothId(@Param("photoBoothId") Long photoBoothId); + Page findByPhotoBoothId(Long photoboothId, Pageable pageable); } From 2bfea9fd86fab2f251ad98bb51a48d2669849fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Tue, 22 Oct 2024 17:10:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20method=20=EC=B1=85=EC=9E=84=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/adapter/ReviewGetAllAdapter.java | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java index 3cc714f..3668b86 100644 --- a/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java +++ b/outbound/src/main/java/com/pocket/outbound/adapter/review/adapter/ReviewGetAllAdapter.java @@ -39,36 +39,59 @@ public ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable) Page reviews = reviewRepository.findByPhotoBoothId(photoboothId, pageable); - List reviewPreviews = reviews.stream().map(review -> { - List images = reviewImageRepository.findByReviewId(review.getId()); - String imageUrl = images.isEmpty() ? "" : images.get(0).getImage().getImageUrl(); - int imageCount = images.size(); - - - // Booth Features 찾기 - List boothFeatureIds = reviewBoothFeatureRepository.findBoothFeatureIdByReviewId(review.getId()); - List boothFeatures = boothFeatureIds.stream() - .map(boothFeatureId -> boothFeatureRepository.findById(boothFeatureId) - .orElseThrow(() -> new ReviewCustomException(ReviewErrorCode.BOOTH_FEATURE_NOT_FOUND))) - .toList(); - - // Photo Features 찾기 - List photoFeatureIds = reviewPhotoFeatureRepository.findPhotoFeatureIdByReviewId(review.getId()); - List photoFeatures = photoFeatureIds.stream() - .map(photoFeatureId -> photoFeatureRepository.findById(photoFeatureId) - .orElseThrow(() -> new ReviewCustomException(ReviewErrorCode.PHOTO_FEATURE_NOT_FOUND))) - .toList(); - - List descriptions = new ArrayList<>(); - // BoothFeature descriptions - boothFeatures.forEach(boothFeature -> descriptions.add(boothFeature.getBoothFeature().getDescription())); - // PhotoFeature descriptions - photoFeatures.forEach(photoFeature -> descriptions.add(photoFeature.getPhotoFeature().getDescription())); - - return reviewOutBoundMapper.toReviewPreviewDto(descriptions, review, imageUrl, imageCount); - }).collect(Collectors.toList()); + List reviewPreviews = reviews.stream() + .map(this::createReviewPreview) + .collect(Collectors.toList()); return new ReviewGetResponseDto(totalReviewCount, reviewPreviews); } + private ReviewPreviewDto createReviewPreview(JpaReview review) { + String imageUrl = getFirstImageUrlForReview(review.getId()); + int imageCount = getReviewImageCount(review.getId()); + + List descriptions = getDescriptionsForReview(review); + + return reviewOutBoundMapper.toReviewPreviewDto(descriptions, review, imageUrl, imageCount); + } + + private String getFirstImageUrlForReview(Long reviewId) { + List images = reviewImageRepository.findByReviewId(reviewId); + return images.isEmpty() ? "" : images.get(0).getImage().getImageUrl(); + } + + private int getReviewImageCount(Long reviewId) { + List images = reviewImageRepository.findByReviewId(reviewId); + return images.size(); + } + + private List getDescriptionsForReview(JpaReview review) { + List descriptions = new ArrayList<>(); + + List boothFeatureIds = reviewBoothFeatureRepository.findBoothFeatureIdByReviewId(review.getId()); + List boothFeatures = getBoothFeatures(boothFeatureIds); + boothFeatures.forEach(boothFeature -> descriptions.add(boothFeature.getBoothFeature().getDescription())); + + List photoFeatureIds = reviewPhotoFeatureRepository.findPhotoFeatureIdByReviewId(review.getId()); + List photoFeatures = getPhotoFeatures(photoFeatureIds); + photoFeatures.forEach(photoFeature -> descriptions.add(photoFeature.getPhotoFeature().getDescription())); + + return descriptions; + } + + private List getBoothFeatures(List boothFeatureIds) { + return boothFeatureIds.stream() + .map(boothFeatureId -> boothFeatureRepository.findById(boothFeatureId) + .orElseThrow(() -> new ReviewCustomException(ReviewErrorCode.BOOTH_FEATURE_NOT_FOUND))) + .collect(Collectors.toList()); + } + + private List getPhotoFeatures(List photoFeatureIds) { + return photoFeatureIds.stream() + .map(photoFeatureId -> photoFeatureRepository.findById(photoFeatureId) + .orElseThrow(() -> new ReviewCustomException(ReviewErrorCode.PHOTO_FEATURE_NOT_FOUND))) + .collect(Collectors.toList()); + } + + }