Skip to content

Commit

Permalink
fix:비회원 장바구니 주문 버그 수정 (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
hseungho authored May 9, 2023
1 parent 7401402 commit c49b8a0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface OrderCreateService {

PaymentVBankResponseDto createVBankPaymentOrdersByCarts(String authId, OrderCreateRequestDto dto);

PaymentCardResponseDto createCardPaymentOrdersByCartsForGuest(String authId, OrderCreateRequestDto dto);

PaymentVBankResponseDto createVBankPaymentOrdersByCartsForGuest(String authId, OrderCreateRequestDto dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public PaymentVBankResponseDto createVBankPaymentOrdersByCarts(String authId, Or
return PaymentVBankResponseDto.of(order.getId());
}

@Override
public PaymentCardResponseDto createCardPaymentOrdersByCartsForGuest(String authId, OrderCreateRequestDto dto) {
Orders order = this.saveOrderByCartsForGuest(authId, dto);
this.saveCardPayment(order);
return PaymentCardResponseDto.of(order.getId(), order.getAmount());
}

@Override
public PaymentVBankResponseDto createVBankPaymentOrdersByCartsForGuest(String authId, OrderCreateRequestDto dto) {
Orders order = this.saveOrderByCartsForGuest(authId, dto);
this.saveVBankPayment(dto, order);
return PaymentVBankResponseDto.of(order.getId());
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* private method area */
private Orders saveOrder(String authId, OrderCreateRequestDto dto, MultipartFile imageFile) {
Expand Down Expand Up @@ -125,6 +139,19 @@ private Orders saveOrderByCarts(String authId, OrderCreateRequestDto dto) {
return order;
}

private Orders saveOrderByCartsForGuest(String authId, OrderCreateRequestDto dto) {
List<CustomProduct> customProducts = this.getCustomProducts(authId, dto);

OrderDestination orderDestination = this.createOrderDestination(dto);
Orders order = ordersRepository.save(Orders.create(orderDestination.getReceiverPhoneNumber(), orderDestination));

customProducts.forEach(customProduct -> customProduct.associateWithOrder(order));

order.calculateTotalValueAndSet();

return order;
}

private Product getProduct(OrderCreateRequestDto dto) {
return productRepository.findByName(dto.getProductDto().getProductName())
.orElseThrow(() -> new ResourceNotFoundException(RESOURCE_NAME_PRODUCT, PARAM_NAME_PRODUCT_NAME, dto.getProductDto().getProductName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public PaymentCardResponseDto createCardPaymentOrdersByCarts(
@RequestHeader(HttpHeaders.AUTHORIZATION) String guestId,
@RequestBody @Validated OrderCreateRequestDto dto
) {
return orderCreateService.createCardPaymentOrdersByCarts(guestId, dto);
return orderCreateService.createCardPaymentOrdersByCartsForGuest(guestId, dto);
}

@PostMapping("/guest/orders/vbank/carts")
Expand All @@ -62,7 +62,7 @@ public PaymentVBankResponseDto createVBankPaymentOrdersByCarts(
@RequestHeader(HttpHeaders.AUTHORIZATION) String guestId,
@RequestBody @Validated OrderCreateRequestDto dto
) {
return orderCreateService.createVBankPaymentOrdersByCarts(guestId, dto);
return orderCreateService.createVBankPaymentOrdersByCartsForGuest(guestId, dto);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,77 @@ void test_registerVBankPaymentOrdersByCarts() {
Assertions.assertEquals("tester", ((VBankPayment.VBankPaymentInfo)(order.getPayment().getInfoAsDto())).getDepositorName());
}

@Test
void test_createOrdersByCartForGuest() {
final String receiverPhoneNum = "01012341234";
List<String> customProductIdList = cartItemRetriveService.retriveAuthCartItem(aid).stream()
.map(CartItemResponse::getId).toList();

PaymentCardResponseDto orderResponseDto = orderCreateService.createCardPaymentOrdersByCartsForGuest(
aid,
OrderCreateRequestDto.forTestCardByCarts(customProductIdList, "receiverName", "receiverEmail", receiverPhoneNum, "address1", "address2", "zipCode")
);
String orderId = orderResponseDto.getMerchantId();
Orders order = ordersRepository.findById(orderId).get();

Assertions.assertEquals(receiverPhoneNum, order.getAuthId());
Assertions.assertEquals(3, order.getCustomProducts().size());
Assertions.assertEquals(6, order.getTotalQuantity());
Assertions.assertEquals("receiverName", order.getOrderDestination().getReceiverName());
Assertions.assertEquals("receiverEmail", order.getOrderDestination().getReceiverEmail());
Assertions.assertEquals(receiverPhoneNum, order.getOrderDestination().getReceiverPhoneNumber());
Assertions.assertEquals("address1", order.getOrderDestination().getAddress1());
Assertions.assertEquals("address2", order.getOrderDestination().getAddress2());
Assertions.assertEquals("zipCode", order.getOrderDestination().getZipCode());

Assertions.assertEquals(OrderStatus.READY, order.getOrderStatus());
Assertions.assertNotEquals(0, order.getAmount());

Assertions.assertEquals(PaymentType.CARD, order.getPayment().getType());
Assertions.assertEquals(PaymentStatus.READY, order.getPayment().getStatus());
Assertions.assertSame(order, order.getPayment().getOrders());
Assertions.assertTrue(order.getPayment().getInfoAsString().isBlank());
}

@Test
void test_test_createOrdersByVBankForGuest() {
final String receiverPhoneNum = "01012341234";
List<String> customProductIdList = cartItemRetriveService.retriveAuthCartItem(aid).stream()
.map(CartItemResponse::getId).toList();

PaymentVBankResponseDto orderResponseDto = orderCreateService.createVBankPaymentOrdersByCartsForGuest(
aid,
OrderCreateRequestDto.forTestVBankByCarts(
customProductIdList,
"receiverName", "receiverEmail", receiverPhoneNum, "address1", "address2", "zipCode",
"하나은행 1234123412341234 리버티", "tester"
)
);

String orderId = orderResponseDto.getOrderId();
Orders order = ordersRepository.findById(orderId).get();

Assertions.assertNotNull(order);
Assertions.assertEquals(receiverPhoneNum, order.getAuthId());
Assertions.assertEquals(3, order.getCustomProducts().size());
Assertions.assertEquals(6, order.getTotalQuantity());
Assertions.assertEquals("receiverName", order.getOrderDestination().getReceiverName());
Assertions.assertEquals("receiverEmail", order.getOrderDestination().getReceiverEmail());
Assertions.assertEquals(receiverPhoneNum, order.getOrderDestination().getReceiverPhoneNumber());
Assertions.assertEquals("address1", order.getOrderDestination().getAddress1());
Assertions.assertEquals("address2", order.getOrderDestination().getAddress2());
Assertions.assertEquals("zipCode", order.getOrderDestination().getZipCode());

Assertions.assertEquals(OrderStatus.WAITING_DEPOSIT, order.getOrderStatus());
Assertions.assertNotEquals(0, order.getAmount());

Assertions.assertEquals(PaymentType.VBANK, order.getPayment().getType());
Assertions.assertEquals(PaymentStatus.READY, order.getPayment().getStatus());
Assertions.assertNotEquals("", order.getPayment().getInfoAsString());
Assertions.assertEquals("하나은행 1234123412341234 리버티", ((VBankPayment.VBankPaymentInfo)(order.getPayment().getInfoAsDto())).getVbankInfo());
Assertions.assertEquals("tester", ((VBankPayment.VBankPaymentInfo)(order.getPayment().getInfoAsDto())).getDepositorName());

}

@BeforeEach
void initCarts() {
Expand Down

0 comments on commit c49b8a0

Please sign in to comment.