Skip to content

Commit

Permalink
fix(#154): 사전 예약 주문 생성 오류 해결 (null 체크 추가)
Browse files Browse the repository at this point in the history
  • Loading branch information
eggnee committed Oct 22, 2024
1 parent 3339d69 commit d75f96f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sparta.order.server.domain.model.Order;
import com.sparta.order.server.domain.model.OrderProduct;
import com.sparta.order.server.domain.model.vo.OrderType;
import com.sparta.order.server.domain.repository.OrderProductRepository;
import com.sparta.order.server.domain.repository.OrderRepository;
import com.sparta.order.server.exception.OrderErrorCode;
Expand Down Expand Up @@ -80,7 +81,8 @@ public Long createOrder(Long userId, OrderCreateRequest request) {
Long savedOrderId = orderRepository.save(order).getOrderId();

// 포인트 유효성 검사 및 사용
if (request.getPointPrice().compareTo(BigDecimal.ZERO) > 0) {
if (request.getPointPrice() != null
&& request.getPointPrice().compareTo(BigDecimal.ZERO) > 0) {
PointHistoryDto pointHistoryRequest = new PointHistoryDto(userId, savedOrderId,
request.getPointPrice(), POINT_HISTORY_TYPE_USE, POINT_DESCRIPTION_ORDER_PAYMENT);

Expand All @@ -104,7 +106,10 @@ public Long createOrder(Long userId, OrderCreateRequest request) {
productPrices.get(productInfo.getProductId()),
productNames.get(productInfo.getProductId()), order));

cartService.orderCartProduct(userId, productQuantities);
if (order.getType().equals(OrderType.STANDARD)) {
cartService.orderCartProduct(userId, productQuantities);
}

payment(userId, order, user.getEmail());
return savedOrderId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class Order extends BaseEntity {
@Column(nullable = false, columnDefinition = "int default 0")
private BigDecimal pointPrice;

@Column(nullable = false)
@Column(nullable = false, columnDefinition = "int default 0")
private BigDecimal couponPrice;

@Column(nullable = true, length = 255)
Expand All @@ -107,6 +107,7 @@ public class Order extends BaseEntity {
private String shippingAddress;

@Column(nullable = false)
@Builder.Default
private Boolean isDeleted = false;

@OneToMany(mappedBy = "order")
Expand Down Expand Up @@ -167,8 +168,8 @@ public static Order createOrder(Long userId, OrderCreateRequest request,
.totalAmount(priceInfo.totalAmount)
.shippingAmount(priceInfo.shippingAmount)
.totalRealAmount(priceInfo.totalRealAmount)
.pointPrice(request.getPointPrice())
.couponPrice(couponPrice)
.pointPrice(request.getPointPrice() != null ? request.getPointPrice() : BigDecimal.ZERO)
.couponPrice(couponPrice != null ? couponPrice : BigDecimal.ZERO)
.addressAlias(address.getAlias())
.recipient(address.getRecipient())
.phoneNumber(address.getPhoneNumber())
Expand Down Expand Up @@ -200,8 +201,8 @@ private static PriceInfo calculatePrice(OrderCreateRequest request, List<Product
final BigDecimal totalAmount = totalProductAmount.add(shippingAmount);

final BigDecimal totalRealAmount = totalAmount
.subtract(request.getPointPrice())
.subtract(couponPrice);
.subtract(request.getPointPrice() != null ? request.getPointPrice() : BigDecimal.ZERO)
.subtract(couponPrice != null ? couponPrice : BigDecimal.ZERO);

return new PriceInfo(totalQuantity, totalAmount, shippingAmount, totalRealAmount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sparta.product.presentation.request.PreOrderCreateRequest;
import dto.OrderCreateRequest;
import dto.OrderProductInfo;
import java.math.BigDecimal;
import java.util.List;

public class PreOrderMapper {
Expand All @@ -21,7 +22,7 @@ public static PreOrder toEntity(PreOrderCreateRequest request) {

public static OrderCreateRequest toDto(String productId, Long addressId) {
OrderProductInfo orderProduct = new OrderProductInfo(productId, 1, null);
return new OrderCreateRequest("PREORDER", List.of(orderProduct), null, addressId);
return new OrderCreateRequest("PREORDER", List.of(orderProduct), BigDecimal.ZERO, addressId);
}

}

0 comments on commit d75f96f

Please sign in to comment.