Skip to content

Commit

Permalink
✨ Feat: 장바구니 옵션 수정 API 검증 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjin3395 committed Feb 5, 2024
1 parent b07b383 commit 596cc5c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void addCart(CartRequestDTO.cartAddDTO request, Member member) {
if (request.getAmount() + existCart.get().getAmount() > item.getStock()) {
throw new OrderHandler(ErrorStatus.LACK_OF_STOCK);
}

// 장바구니 내역의 수량 업데이트
existCart.get().updateAmount(request.getAmount());
} else { // 장바구니 내역 신규 생성
Expand Down Expand Up @@ -126,8 +126,14 @@ public Cart updateCart(CartRequestDTO.cartUpdateDTO request, Member member) {
}

// 재고 수량과 비교
if (request.getAmount() > cart.getItem().getStock()) {
throw new OrderHandler(ErrorStatus.LACK_OF_STOCK);
if (!cart.getItem().getItemOptionList().isEmpty()) { // 상품 옵션이 있는 경우
if (request.getAmount() > cart.getItemOption().getStock()) {
throw new OrderHandler(ErrorStatus.LACK_OF_STOCK);
}
} else {
if (request.getAmount() > cart.getItem().getStock()) {
throw new OrderHandler(ErrorStatus.LACK_OF_STOCK);
}
}

return cart.updateAmount(request.getAmount());
Expand Down

0 comments on commit 596cc5c

Please sign in to comment.