diff --git a/src/main/java/com/zerozero/core/domain/vo/Review.java b/src/main/java/com/zerozero/core/domain/vo/Review.java index e837c37..b90e8a1 100644 --- a/src/main/java/com/zerozero/core/domain/vo/Review.java +++ b/src/main/java/com/zerozero/core/domain/vo/Review.java @@ -1,10 +1,15 @@ package com.zerozero.core.domain.vo; import com.zerozero.core.domain.shared.ValueObject; +import com.zerozero.core.domain.vo.ZeroDrink.Type; import io.swagger.v3.oas.annotations.media.Schema; import java.io.Serial; import java.io.Serializable; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -33,18 +38,8 @@ public class Review extends ValueObject implements Serializable { @Schema(description = "리뷰 내용", example = "제로 음료 판매중!") private String content; - @Schema(description = "제로 음료수 목록", example = "[\n" + - " {\n" + - " \"type\": \"COCA_COLA_ZERO\"\n" + - " },\n" + - " {\n" + - " \"type\": \"PEPSI_ZERO\"\n" + - " },\n" + - " {\n" + - " \"type\": \"SPRITE_ZERO\"\n" + - " }\n" + - "]") - private ZeroDrink[] zeroDrinks; + @Schema(description = "제로 음료수 목록", example = "[\"COCA_COLA_ZERO\", \"PEPSI_ZERO\", \"SPRITE_ZERO\"]") + private List zeroDrinks; @Schema(description = "작성한 사용자 ID") private UUID userId; @@ -56,7 +51,11 @@ public static Review of(com.zerozero.core.domain.entity.Review review) { return Review.builder() .id(review.getId()) .content(review.getContent()) - .zeroDrinks(review.getZeroDrinks()) + .zeroDrinks(Optional.ofNullable(review.getZeroDrinks()) + .map(zeroDrinks -> Arrays.stream(zeroDrinks) + .map(ZeroDrink::getType) + .collect(Collectors.toList())) + .orElse(null)) .userId(review.getUserId()) .build(); } diff --git a/src/main/java/com/zerozero/review/presentation/CreateStoreReviewController.java b/src/main/java/com/zerozero/review/presentation/CreateStoreReviewController.java index 3fc6c46..ab8b635 100644 --- a/src/main/java/com/zerozero/review/presentation/CreateStoreReviewController.java +++ b/src/main/java/com/zerozero/review/presentation/CreateStoreReviewController.java @@ -5,6 +5,7 @@ import com.zerozero.core.application.BaseResponse; import com.zerozero.core.domain.vo.AccessToken; import com.zerozero.core.domain.vo.ZeroDrink; +import com.zerozero.core.domain.vo.ZeroDrink.Type; import com.zerozero.core.exception.error.GlobalErrorCode; import com.zerozero.review.application.CreateStoreReviewUseCase; import com.zerozero.review.application.CreateStoreReviewUseCase.CreateStoreReviewErrorCode; @@ -12,6 +13,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; import java.util.Optional; import java.util.UUID; import lombok.AccessLevel; @@ -50,7 +52,12 @@ public ResponseEntity createStoreReview(@RequestParam CreateStoreReviewUseCase.CreateStoreReviewRequest.builder() .storeId(storeId) .content(request.getContent()) - .zeroDrinks(request.getZeroDrinks()) + .zeroDrinks(Optional.ofNullable(request.getZeroDrinks()) + .map(zeroDrinks -> zeroDrinks.stream().map(zeroDrink -> ZeroDrink.builder() + .type(zeroDrink) + .build()) + .toArray(ZeroDrink[]::new)) + .orElse(null)) .accessToken(accessToken) .build()); if (createStoreReviewResponse == null || !createStoreReviewResponse.isSuccess()) { @@ -86,17 +93,7 @@ public static class CreateStoreReviewRequest implements BaseRequest { @Schema(description = "리뷰 내용", example = "제로콜라 판매 중!") private String content; - @Schema(description = "제로 음료수 목록", example = "[\n" + - " {\n" + - " \"type\": \"COCA_COLA_ZERO\"\n" + - " },\n" + - " {\n" + - " \"type\": \"PEPSI_ZERO\"\n" + - " },\n" + - " {\n" + - " \"type\": \"SPRITE_ZERO\"\n" + - " }\n" + - "]") - private ZeroDrink[] zeroDrinks; + @Schema(description = "제로 음료수 목록", example = "[\"COCA_COLA_ZERO\", \"PEPSI_ZERO\", \"SPRITE_ZERO\"]") + private List zeroDrinks; } } diff --git a/src/main/java/com/zerozero/review/presentation/UpdateStoreReviewController.java b/src/main/java/com/zerozero/review/presentation/UpdateStoreReviewController.java index 3278638..113324b 100644 --- a/src/main/java/com/zerozero/review/presentation/UpdateStoreReviewController.java +++ b/src/main/java/com/zerozero/review/presentation/UpdateStoreReviewController.java @@ -5,6 +5,7 @@ import com.zerozero.core.application.BaseResponse; import com.zerozero.core.domain.vo.AccessToken; import com.zerozero.core.domain.vo.ZeroDrink; +import com.zerozero.core.domain.vo.ZeroDrink.Type; import com.zerozero.core.exception.error.GlobalErrorCode; import com.zerozero.review.application.UpdateStoreReviewUseCase; import com.zerozero.review.application.UpdateStoreReviewUseCase.UpdateStoreReviewErrorCode; @@ -12,6 +13,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; import java.util.Optional; import java.util.UUID; import lombok.AccessLevel; @@ -50,7 +52,12 @@ public ResponseEntity updateStoreReview(@PathVariable UpdateStoreReviewUseCase.UpdateStoreReviewRequest.builder() .reviewId(reviewId) .content(request.getContent()) - .zeroDrinks(request.getZeroDrink()) + .zeroDrinks(Optional.ofNullable(request.getZeroDrinks()) + .map(zeroDrinks -> zeroDrinks.stream().map(zeroDrink -> ZeroDrink.builder() + .type(zeroDrink) + .build()) + .toArray(ZeroDrink[]::new)) + .orElse(null)) .accessToken(accessToken) .build()); if (updateStoreReviewResponse == null || !updateStoreReviewResponse.isSuccess()) { @@ -86,17 +93,7 @@ public static class UpdateStoreReviewRequest implements BaseRequest { @Schema(description = "리뷰 내용", example = "제로콜라 판매 중!") private String content; - @Schema(description = "제로 음료수 목록", example = "[\n" + - " {\n" + - " \"type\": \"COCA_COLA_ZERO\"\n" + - " },\n" + - " {\n" + - " \"type\": \"PEPSI_ZERO\"\n" + - " },\n" + - " {\n" + - " \"type\": \"SPRITE_ZERO\"\n" + - " }\n" + - "]") - private ZeroDrink[] zeroDrink; + @Schema(description = "제로 음료수 목록", example = "[\"COCA_COLA_ZERO\", \"PEPSI_ZERO\", \"SPRITE_ZERO\"]") + private List zeroDrinks; } } diff --git a/src/main/java/com/zerozero/store/presentation/ReadStoreInfoController.java b/src/main/java/com/zerozero/store/presentation/ReadStoreInfoController.java index 4ae325b..08740ed 100644 --- a/src/main/java/com/zerozero/store/presentation/ReadStoreInfoController.java +++ b/src/main/java/com/zerozero/store/presentation/ReadStoreInfoController.java @@ -7,7 +7,6 @@ import com.zerozero.core.domain.vo.AccessToken; import com.zerozero.core.domain.vo.Store; import com.zerozero.core.domain.vo.User; -import com.zerozero.core.domain.vo.ZeroDrink; import com.zerozero.core.domain.vo.ZeroDrink.Type; import com.zerozero.core.exception.error.GlobalErrorCode; import com.zerozero.review.application.ReadStoreReviewUseCase; @@ -20,6 +19,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -97,16 +97,19 @@ private ReadStoreInfoResponse toResponse(ReadStoreInfoUseCase.ReadStoreInfoRespo .build(); } - private ZeroDrink[] getTop3ZeroDrinks(ReadStoreReviewResponse.Review[] reviews) { - ZeroDrink[] allZeroDrinks = Arrays.stream(reviews).flatMap(review -> Arrays.stream(review.getReview().getZeroDrinks())).toArray(ZeroDrink[]::new); - return Arrays.stream(allZeroDrinks) - .collect(Collectors.groupingBy(ZeroDrink::getType, Collectors.counting())) + private List getTop3ZeroDrinks(ReadStoreReviewResponse.Review[] reviews) { + List allZeroDrinks = Arrays.stream(reviews) + .flatMap(review -> review.getReview().getZeroDrinks().stream()) + .collect(Collectors.toList()); + + return allZeroDrinks.stream() + .collect(Collectors.groupingBy(type -> type, Collectors.counting())) .entrySet().stream() - .sorted(Map.Entry.comparingByValue().reversed()) + .sorted(Map.Entry.comparingByValue().reversed() + .thenComparing(Map.Entry.comparingByKey())) .limit(3) .map(Map.Entry::getKey) - .flatMap(type -> Arrays.stream(allZeroDrinks).filter(drink -> drink.getType() == type)) - .toArray(ZeroDrink[]::new); + .collect(Collectors.toList()); } @ToString @@ -125,7 +128,7 @@ public static class ReadStoreInfoResponse extends BaseResponse private Review[] reviews; @Schema(description = "제로 음료수 순위") - private ZeroDrink[] zeroDrinks; + private List zeroDrinks; record Review(com.zerozero.core.domain.vo.Review review, User user) {