Skip to content

Commit

Permalink
Merge pull request #47 from nowgnas/fix/review-by-user-id
Browse files Browse the repository at this point in the history
🐛 Fix: select review property change
  • Loading branch information
indl1670 authored Dec 21, 2023
2 parents adb6f03 + cb7d042 commit 64a2046
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 143 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
testImplementation 'org.mockito:mockito-core:4.8.0'
implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312180340'
implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312210138'
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'

}
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/kr/bb/product/common/dto/FlowerInformation.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/kr/bb/product/common/dto/IsProductPriceValid.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/kr/bb/product/common/dto/ProductInformation.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/kr/bb/product/common/dto/ProductThumbnail.java

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kr.bb.product.domain.flower.adapter.in.client;

import bloomingblooms.domain.flower.FlowerInformation;
import bloomingblooms.response.CommonResponse;
import java.util.List;
import kr.bb.product.common.dto.FlowerInformation;
import kr.bb.product.domain.flower.application.usecase.FlowerQueryUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kr.bb.product.domain.flower.application.port.in;

import bloomingblooms.domain.flower.FlowerInformation;
import java.util.List;
import java.util.stream.Collectors;
import kr.bb.product.common.dto.FlowerInformation;
import kr.bb.product.domain.flower.application.port.out.FlowerQueryOutPort;
import kr.bb.product.domain.flower.application.usecase.FlowerQueryUseCase;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kr.bb.product.domain.flower.application.usecase;

import bloomingblooms.domain.flower.FlowerInformation;
import java.util.List;
import kr.bb.product.common.dto.FlowerInformation;

public interface FlowerQueryUseCase {
List<FlowerInformation> getAllFlowers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kr.bb.product.domain.product.adapter.in.client;

import bloomingblooms.domain.product.IsProductPriceValid;
import bloomingblooms.domain.product.ProductInformation;
import bloomingblooms.domain.product.ProductThumbnail;
import bloomingblooms.domain.product.StoreSubscriptionProductId;
import bloomingblooms.domain.product.SubscriptionProductInformation;
import bloomingblooms.response.CommonResponse;
import java.util.List;
import kr.bb.product.common.dto.IsProductPriceValid;
import kr.bb.product.common.dto.ProductInformation;
import kr.bb.product.common.dto.ProductThumbnail;
import kr.bb.product.common.dto.StoreSubscriptionProductId;
import kr.bb.product.common.dto.SubscriptionProductInformation;
import kr.bb.product.domain.product.application.usecase.ProductQueryUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package kr.bb.product.domain.product.adapter.out.mongo;

import bloomingblooms.domain.product.IsProductPriceValid;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import kr.bb.product.common.dto.IsProductPriceValid;
import kr.bb.product.domain.product.application.port.out.ProductQueryOutPort;
import kr.bb.product.domain.product.entity.Product;
import kr.bb.product.domain.product.entity.ProductCommand.SelectOption;
Expand Down Expand Up @@ -159,4 +159,14 @@ public boolean findProductPriceValid(List<IsProductPriceValid> productPriceValid
return productPriceValids.stream()
.allMatch(item -> item.getPrice().equals(collect1.get(item.getProductId())));
}

@Override
public Map<String, String> findProductNameByProductIdsForReviewByUserId(List<String> productIds) {

List<Product> products =
mongoTemplate.find(Query.query(Criteria.where("_id").in(productIds)), Product.class);

return products.stream()
.collect(Collectors.toMap(Product::getProductId, Product::getProductName));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package kr.bb.product.domain.product.application.port.in;

import bloomingblooms.domain.product.IsProductPriceValid;
import bloomingblooms.domain.product.ProductInformation;
import bloomingblooms.domain.product.ProductThumbnail;
import bloomingblooms.domain.product.StoreSubscriptionProductId;
import bloomingblooms.domain.product.SubscriptionProductInformation;
import bloomingblooms.errors.EntityNotFoundException;
import java.util.List;
import java.util.stream.Collectors;
import kr.bb.product.common.dto.IsProductPriceValid;
import kr.bb.product.common.dto.ProductInformation;
import kr.bb.product.common.dto.ProductThumbnail;
import kr.bb.product.common.dto.StoreSubscriptionProductId;
import kr.bb.product.common.dto.SubscriptionProductInformation;
import kr.bb.product.domain.flower.adapter.out.jpa.FlowerJpaRepository;
import kr.bb.product.domain.flower.application.port.out.FlowerQueryOutPort;
import kr.bb.product.domain.flower.entity.Flower;
Expand Down Expand Up @@ -261,13 +261,13 @@ public SubscriptionProductForCustomer getSubscriptionProductDetail(Long storeId)

@Override
public ProductThumbnail getProductThumbnail(String productId) {
return ProductThumbnail.getData(productQueryOutPort.findByProductId(productId));
return ProductCommand.getProductThumbnailData(productQueryOutPort.findByProductId(productId));
}

@Override
public List<ProductInformation> getProductInformation(List<String> productIds) {
List<Product> productByProductIds = productQueryOutPort.findProductByProductIds(productIds);
return ProductInformation.getData(productByProductIds);
return ProductCommand.getProductInformationListData(productByProductIds);
}

@Override
Expand All @@ -278,13 +278,14 @@ public void getProductPriceValidation(List<IsProductPriceValid> productPriceVali

@Override
public StoreSubscriptionProductId getStoreSubscriptionProductId(Long storeId) {
return StoreSubscriptionProductId.getData(
return ProductCommand.getStoreSubscriptionProductIdData(
productQueryOutPort.findSubscriptionProductByStoreId(storeId));
}

@Override
public SubscriptionProductInformation getSubscriptionProductInformation(String productId) {
return SubscriptionProductInformation.getData(productQueryOutPort.findByProductId(productId));
return ProductCommand.getSubscriptionProductInformationData(
productQueryOutPort.findByProductId(productId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package kr.bb.product.domain.product.application.port.out;

import bloomingblooms.domain.product.IsProductPriceValid;
import java.util.List;
import kr.bb.product.common.dto.IsProductPriceValid;
import java.util.Map;
import kr.bb.product.domain.product.entity.Product;
import kr.bb.product.domain.product.entity.ProductCommand;
import kr.bb.product.domain.product.entity.ProductSaleStatus;
Expand Down Expand Up @@ -31,4 +32,6 @@ Page<Product> findStoreProducts(
List<Product> findProductByProductIds(List<String> productIds);

boolean findProductPriceValid(List<IsProductPriceValid> productPriceValids);

Map<String, String> findProductNameByProductIdsForReviewByUserId(List<String> productIds);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package kr.bb.product.domain.product.application.usecase;

import bloomingblooms.domain.product.IsProductPriceValid;
import bloomingblooms.domain.product.ProductInformation;
import bloomingblooms.domain.product.ProductThumbnail;
import bloomingblooms.domain.product.StoreSubscriptionProductId;
import bloomingblooms.domain.product.SubscriptionProductInformation;
import java.util.List;
import kr.bb.product.common.dto.IsProductPriceValid;
import kr.bb.product.common.dto.ProductInformation;
import kr.bb.product.common.dto.ProductThumbnail;
import kr.bb.product.common.dto.StoreSubscriptionProductId;
import kr.bb.product.common.dto.SubscriptionProductInformation;
import kr.bb.product.domain.product.entity.ProductCommand;
import kr.bb.product.domain.product.entity.ProductCommand.ProductList;
import kr.bb.product.domain.product.entity.ProductCommand.SortOption;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package kr.bb.product.domain.product.entity;

import bloomingblooms.domain.product.ProductInformation;
import bloomingblooms.domain.product.ProductThumbnail;
import bloomingblooms.domain.product.StoreSubscriptionProductId;
import bloomingblooms.domain.product.SubscriptionProductInformation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -450,4 +454,32 @@ public void setLiked(Boolean liked) {
isLiked = liked;
}
}
public static List<ProductInformation> getProductInformationListData(List<Product> productByProductIds) {
return productByProductIds.stream()
.map(
item ->
ProductInformation.builder()
.productId(item.getProductId())
.productName(item.getProductName())
.productThumbnail(item.getProductThumbnail())
.build())
.collect(Collectors.toList());
}
public static ProductThumbnail getProductThumbnailData(Product byProductId) {
return ProductThumbnail.builder().productThumbnail(byProductId.getProductThumbnail()).build();
}
public static StoreSubscriptionProductId getStoreSubscriptionProductIdData(Product subscriptionProductByStoreId) {
return StoreSubscriptionProductId.builder()
.subscriptionProductId(subscriptionProductByStoreId.getProductId())
.build();
}
public static SubscriptionProductInformation getSubscriptionProductInformationData(Product product) {
return SubscriptionProductInformation.builder()
.productName(product.getProductName())
.productThumbnail(product.getProductThumbnail())
.unitPrice(product.getProductPrice())
.storeId(product.getStoreId())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
public interface WishlistServiceClient {

@CircuitBreaker(name = "getProductsMemberLikesFallback", fallbackMethod = "getProductsMemberLikesFallback")
@PostMapping("/likes/{userId}")
@PostMapping("/client/likes/{userId}")
CommonResponse<List<String>> getProductsMemberLikes(
@PathVariable Long userId, List<String> productIds);

@CircuitBreaker(name = "getProductDetailLikesFallback", fallbackMethod = "getProductDetailLikesFallback")
@GetMapping("/likes/{userId}/product/{productId}")
@GetMapping("/client/likes/{userId}/product/{productId}")
CommonResponse<ProductDetailLike> getProductDetailLikes(
@PathVariable String productId, @PathVariable Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public ReviewCommand.ProductDetailReviewList findReviewsByProductId(
@Override
public ReviewList findReviewsByUserId(Long userId, Pageable pageable, SortOption sortOption) {
Pageable pageRequest = getPageable(pageable, sortOption);
Page<Review> reviewsByUserId = reviewQueryOutPort.findReviewsByUserId(userId, pageRequest);
List<String> productIds =
reviewsByUserId.getContent().stream()
.map(Review::getProductId)
.collect(Collectors.toList());
return ReviewCommand.ReviewList.getData(
reviewQueryOutPort.findReviewsByUserId(userId, pageRequest));
reviewsByUserId,
productQueryOutPort.findProductNameByProductIdsForReviewByUserId(productIds));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static class ReviewItem {
private List<String> reviewImages;
private String nickname;
private String profileImage;
private String productName;
}

@Getter
Expand All @@ -150,7 +151,8 @@ public static class ReviewList {
private List<ReviewItem> reviews;
private int totalCnt;

public static ReviewList getData(Page<Review> reviewsByUserId) {
public static ReviewList getData(
Page<Review> reviewsByUserId, Map<String, String> productNames) {
return ReviewList.builder()
.reviews(
reviewsByUserId.getContent().stream()
Expand All @@ -160,6 +162,7 @@ public static ReviewList getData(Page<Review> reviewsByUserId) {
.reviewId(item.getReviewId())
.createdAt(item.getCreatedAt())
.nickname(item.getNickname())
.productName(productNames.get(item.getProductId()))
.profileImage(item.getProfileImage())
.reviewContent(item.getReviewContent())
.reviewImages(
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/kr/bb/product/config/mock/MockingApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MockingApi {
public static void setUpProductDetailLikes(WireMockServer mockCacheApi) {
mockCacheApi.stubFor(
WireMock.get(WireMock.urlMatching("/likes/1/product/123"))
WireMock.get(WireMock.urlMatching("/client/likes/1/product/123"))
.willReturn(
WireMock.aResponse()
.withStatus(HttpStatus.OK.value())
Expand All @@ -17,7 +17,7 @@ public static void setUpProductDetailLikes(WireMockServer mockCacheApi) {
}
public static void setUpProductsLikes(WireMockServer mockCacheApi) {
mockCacheApi.stubFor(
WireMock.post(WireMock.urlMatching("/likes/1"))
WireMock.post(WireMock.urlMatching("/client/likes/1"))
.willReturn(
WireMock.aResponse()
.withStatus(HttpStatus.OK.value())
Expand Down
Loading

0 comments on commit 64a2046

Please sign in to comment.