diff --git a/src/main/java/com/flab/shoeauction/controller/TradeApiController.java b/src/main/java/com/flab/shoeauction/controller/TradeApiController.java index 2242257..9ba610f 100644 --- a/src/main/java/com/flab/shoeauction/controller/TradeApiController.java +++ b/src/main/java/com/flab/shoeauction/controller/TradeApiController.java @@ -117,13 +117,14 @@ public void updateForwardingTrackingNumber(@PathVariable Long id, @LoginCheck(authority = UserLevel.AUTH) @PatchMapping("/{id}/purchase-confirmation") - public void ConfirmPurchase(@PathVariable Long id, @CurrentUser String email) { + public void confirmPurchase(@PathVariable Long id, @CurrentUser String email) { tradeService.confirmPurchase(id, email); } @LoginCheck(authority = UserLevel.ADMIN) @GetMapping - public Page getTradeInfos(TradeSearchCondition tradeSearchCondition, Pageable pageable) { + public Page getTradeInfos(TradeSearchCondition tradeSearchCondition, + Pageable pageable) { return tradeService.getTradeInfos(tradeSearchCondition, pageable); } } \ No newline at end of file diff --git a/src/main/java/com/flab/shoeauction/controller/dto/ProductDto.java b/src/main/java/com/flab/shoeauction/controller/dto/ProductDto.java index 7da2dc0..79e20ad 100644 --- a/src/main/java/com/flab/shoeauction/controller/dto/ProductDto.java +++ b/src/main/java/com/flab/shoeauction/controller/dto/ProductDto.java @@ -2,6 +2,7 @@ import com.flab.shoeauction.controller.dto.BrandDto.BrandInfo; import com.flab.shoeauction.controller.dto.TradeDto.TradeBidResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeCompleteInfo; import com.flab.shoeauction.domain.brand.Brand; import com.flab.shoeauction.domain.product.Product; import com.flab.shoeauction.domain.product.common.Currency; @@ -135,6 +136,7 @@ public static class ProductInfoResponse { private BrandInfo brand; private List saleBids = new ArrayList<>(); private List purchaseBids = new ArrayList<>(); + private List tradeCompleteInfos = new ArrayList<>(); } diff --git a/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java b/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java index cdaccf5..18a5911 100644 --- a/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java +++ b/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java @@ -7,6 +7,7 @@ import com.flab.shoeauction.domain.trade.Trade; import com.flab.shoeauction.domain.trade.TradeStatus; import com.flab.shoeauction.domain.users.user.User; +import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -175,7 +176,6 @@ public boolean isSearchByBuyer() { @Getter @NoArgsConstructor public static class TradeInfoResponse { - private Long id; private TradeStatus status; @@ -185,4 +185,19 @@ public TradeInfoResponse(Long id, TradeStatus status) { this.status = status; } } + + @Getter + @NoArgsConstructor + public static class TradeCompleteInfo { + private double productSize; + private Long price; + private LocalDateTime completeTime; + + @Builder + public TradeCompleteInfo(double productSize, Long price, LocalDateTime completeTime) { + this.productSize = productSize; + this.price = price; + this.completeTime = completeTime; + } + } } \ No newline at end of file diff --git a/src/main/java/com/flab/shoeauction/domain/product/Product.java b/src/main/java/com/flab/shoeauction/domain/product/Product.java index d798aff..76c52e5 100644 --- a/src/main/java/com/flab/shoeauction/domain/product/Product.java +++ b/src/main/java/com/flab/shoeauction/domain/product/Product.java @@ -1,9 +1,12 @@ package com.flab.shoeauction.domain.product; +import static java.util.stream.Collectors.toList; + import com.flab.shoeauction.controller.dto.ProductDto.ProductInfoByTrade; import com.flab.shoeauction.controller.dto.ProductDto.ProductInfoResponse; import com.flab.shoeauction.controller.dto.ProductDto.SaveRequest; import com.flab.shoeauction.controller.dto.TradeDto.TradeBidResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeCompleteInfo; import com.flab.shoeauction.domain.BaseTimeEntity; import com.flab.shoeauction.domain.brand.Brand; import com.flab.shoeauction.domain.product.common.Currency; @@ -17,7 +20,6 @@ import java.util.Comparator; import java.util.List; import java.util.function.Predicate; -import java.util.stream.Collectors; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -112,10 +114,19 @@ public ProductInfoResponse toProductInfoResponse() { .resizedImagePath(this.resizedImagePath) .saleBids(getSaleBids()) .purchaseBids(getPurchaseBids()) + .tradeCompleteInfos(getTradeCompletes()) .brand(brand.toBrandInfo()) .build(); } + private List getTradeCompletes() { + return trades.stream() + .filter(t->t.getStatus().equals(TradeStatus.TRADE_COMPLETE)) + .map(Trade::toTradeCompleteInfo) + .sorted(Comparator.comparing(TradeCompleteInfo::getCompleteTime).reversed()) + .collect(toList()); + } + public ProductInfoByTrade toProductInfoByTrade(User currentUser, double size) { return ProductInfoByTrade.builder() @@ -164,7 +175,7 @@ private List getSaleBids() { .filter(v -> v.getStatus() == TradeStatus.PRE_CONCLUSION && v.getBuyer() == null) .sorted(Comparator.comparing(Trade::getPrice)) .map(Trade::toTradeBidResponse) - .collect(Collectors.toList()); + .collect(toList()); } private List getPurchaseBids() { @@ -172,7 +183,7 @@ private List getPurchaseBids() { .filter(v -> v.getStatus() == TradeStatus.PRE_CONCLUSION && v.getSeller() == null) .sorted(Comparator.comparing(Trade::getPrice).reversed()) .map(Trade::toTradeBidResponse) - .collect(Collectors.toList()); + .collect(toList()); } diff --git a/src/main/java/com/flab/shoeauction/domain/trade/Trade.java b/src/main/java/com/flab/shoeauction/domain/trade/Trade.java index 9c2b6cd..3f8fbf3 100644 --- a/src/main/java/com/flab/shoeauction/domain/trade/Trade.java +++ b/src/main/java/com/flab/shoeauction/domain/trade/Trade.java @@ -1,6 +1,7 @@ package com.flab.shoeauction.domain.trade; import com.flab.shoeauction.controller.dto.TradeDto.TradeBidResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeCompleteInfo; import com.flab.shoeauction.domain.BaseTimeEntity; import com.flab.shoeauction.domain.addressBook.Address; import com.flab.shoeauction.domain.product.Product; @@ -92,6 +93,14 @@ public TradeBidResponse toTradeBidResponse() { .build(); } + public TradeCompleteInfo toTradeCompleteInfo() { + return TradeCompleteInfo.builder() + .productSize(this.productSize) + .price(this.price) + .completeTime(this.getModifiedDate()) + .build(); + } + public void makeImmediatePurchase(User buyer, Address shippingAddress) { this.shippingAddress = shippingAddress; this.buyer = buyer; diff --git a/src/main/java/com/flab/shoeauction/service/ProductService.java b/src/main/java/com/flab/shoeauction/service/ProductService.java index d54b1e6..fe6f4e2 100644 --- a/src/main/java/com/flab/shoeauction/service/ProductService.java +++ b/src/main/java/com/flab/shoeauction/service/ProductService.java @@ -46,7 +46,7 @@ public void saveProduct(SaveRequest requestDto, @Nullable MultipartFile productI @Cacheable(value = "product", key = "#id") public ProductInfoResponse getProductInfo(Long id) { return productRepository.findById(id).orElseThrow( - () -> new ProductNotFoundException()) + ProductNotFoundException::new) .toProductInfoResponse(); } diff --git a/src/test/java/com/flab/shoeauction/controller/ProductApiControllerTest.java b/src/test/java/com/flab/shoeauction/controller/ProductApiControllerTest.java index a326d9e..6c6a7da 100644 --- a/src/test/java/com/flab/shoeauction/controller/ProductApiControllerTest.java +++ b/src/test/java/com/flab/shoeauction/controller/ProductApiControllerTest.java @@ -28,6 +28,7 @@ import com.flab.shoeauction.controller.dto.ProductDto.SearchCondition; import com.flab.shoeauction.controller.dto.ProductDto.ThumbnailResponse; import com.flab.shoeauction.controller.dto.TradeDto.TradeBidResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeCompleteInfo; import com.flab.shoeauction.domain.product.common.Currency; import com.flab.shoeauction.domain.product.common.OrderStandard; import com.flab.shoeauction.domain.product.common.SizeClassification; @@ -37,6 +38,7 @@ import com.flab.shoeauction.service.SessionLoginService; import java.nio.charset.StandardCharsets; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -143,9 +145,21 @@ private ProductInfoResponse createProductInfo() { "https://shoeauction-brands-resized.s3.ap-northeast-2.amazonaws.com/brand.png") .purchaseBids(createPurchaseBids()) .saleBids(createSales()) + .tradeCompleteInfos(createCompleteTrades()) .build(); } + private List createCompleteTrades() { + List list = new ArrayList<>(); + TradeCompleteInfo tradeCompleteInfo = TradeCompleteInfo.builder() + .completeTime(LocalDateTime.now()) + .price(300000L) + .productSize(280.0) + .build(); + list.add(tradeCompleteInfo); + return list; + } + private ThumbnailResponse createProductThumbnail() { return ThumbnailResponse.builder() .id(99L) @@ -340,7 +354,13 @@ void getProductInfo() throws Exception { fieldWithPath("purchaseBids.[].productSize").type(JsonFieldType.NUMBER) .description("구매 입찰 물품 사이즈"), fieldWithPath("purchaseBids.[].price").type(JsonFieldType.NUMBER) - .description("구매 입찰 물품 가격") + .description("구매 입찰 물품 가격"), + fieldWithPath("tradeCompleteInfos.[].productSize").type(JsonFieldType.NUMBER) + .description("완료된 거래의 물품 사이즈"), + fieldWithPath("tradeCompleteInfos.[].price").type(JsonFieldType.NUMBER) + .description("완료된 거래의 물품 가격"), + fieldWithPath("tradeCompleteInfos.[].completeTime").type(JsonFieldType.STRING) + .description("거래 완료 시간") ) )); } diff --git a/src/test/java/com/flab/shoeauction/service/ProductServiceTest.java b/src/test/java/com/flab/shoeauction/service/ProductServiceTest.java index aa092fb..95eca77 100644 --- a/src/test/java/com/flab/shoeauction/service/ProductServiceTest.java +++ b/src/test/java/com/flab/shoeauction/service/ProductServiceTest.java @@ -180,6 +180,19 @@ private List createTrades() { .shippingAddress(address) .build(); list.add(purchase); + + Trade completeTrade = Trade.builder() + .publisher(user) + .seller(user) + .buyer(null) + .product(product) + .status(TradeStatus.TRADE_COMPLETE) + .price(300000L) + .productSize(260.0) + .returnAddress(address) + .shippingAddress(null) + .build(); + list.add(completeTrade); return list; }