Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
feat : 시세 변동 추이 확인을 위한 거래 완료 내역 제공
Browse files Browse the repository at this point in the history
1. Product 조회시 관련 trade에 대한 완료 내역 제공
 - 거래 완료 날짜
 - 가격
 - 사이즈
 - 날짜 내림차순으로 정렬
  • Loading branch information
kihyuk-jeong committed May 21, 2021
1 parent 21a8fc6 commit 69f791a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TradeInfoResponse> getTradeInfos(TradeSearchCondition tradeSearchCondition, Pageable pageable) {
public Page<TradeInfoResponse> getTradeInfos(TradeSearchCondition tradeSearchCondition,
Pageable pageable) {
return tradeService.getTradeInfos(tradeSearchCondition, pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,6 +136,7 @@ public static class ProductInfoResponse {
private BrandInfo brand;
private List<TradeBidResponse> saleBids = new ArrayList<>();
private List<TradeBidResponse> purchaseBids = new ArrayList<>();
private List<TradeCompleteInfo> tradeCompleteInfos = new ArrayList<>();

}

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,7 +176,6 @@ public boolean isSearchByBuyer() {
@Getter
@NoArgsConstructor
public static class TradeInfoResponse {

private Long id;
private TradeStatus status;

Expand All @@ -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;
}
}
}
17 changes: 14 additions & 3 deletions src/main/java/com/flab/shoeauction/domain/product/Product.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -112,10 +114,19 @@ public ProductInfoResponse toProductInfoResponse() {
.resizedImagePath(this.resizedImagePath)
.saleBids(getSaleBids())
.purchaseBids(getPurchaseBids())
.tradeCompleteInfos(getTradeCompletes())
.brand(brand.toBrandInfo())
.build();
}

private List<TradeCompleteInfo> 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()
Expand Down Expand Up @@ -164,15 +175,15 @@ private List<TradeBidResponse> 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<TradeBidResponse> getPurchaseBids() {
return getTrades().stream()
.filter(v -> v.getStatus() == TradeStatus.PRE_CONCLUSION && v.getSeller() == null)
.sorted(Comparator.comparing(Trade::getPrice).reversed())
.map(Trade::toTradeBidResponse)
.collect(Collectors.toList());
.collect(toList());
}


Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/flab/shoeauction/domain/trade/Trade.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<TradeCompleteInfo> createCompleteTrades() {
List<TradeCompleteInfo> 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)
Expand Down Expand Up @@ -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("거래 완료 시간")
)
));
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/flab/shoeauction/service/ProductServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ private List<Trade> 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;
}

Expand Down

0 comments on commit 69f791a

Please sign in to comment.