[Fix] 장바구니 추가 시 검증 추가, 상품 옵션 조회 API 추가#96
Conversation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
WalkthroughCartService에 상품 옵션(ProductOption) 조회 및 재고 검증 로직을 추가하고, ProductService/ProductController에 상품 옵션 조회 API를 도입하며 관련 오류 코드(PRODUCT_OPTION_NOT_FOUND, OUT_OF_STOCK)를 추가합니다. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/main/java/com/ongil/backend/domain/cart/service/CartService.java`:
- Around line 122-141: In updateCart in CartService: when
selectedSize/selectedColor are changed you must check for an existing cart entry
for the same user/product/size/color (use
cartRepository.findByUserIdAndProductIdAndSelectedSizeAndSelectedColor like
addCart does); if a duplicate exists either merge quantities (sum
existing.getQuantity() + updatedQuantity and validate stock via
productOptionRepository.findByProductIdAndSizeAndColor) and delete the
current/other entry accordingly, or throw a ValidationException to prevent
duplication—ensure you reference cart.getUser().getId(),
cart.getProduct().getId(), updatedSize and updatedColor when querying and still
perform the stock check on productOption before applying the merge or throwing.
🧹 Nitpick comments (1)
src/main/java/com/ongil/backend/domain/cart/service/CartService.java (1)
79-97: 재고 검증의 TOCTOU(Time-of-Check to Time-of-Use) 경합 가능성현재 재고 확인(
productOption.getStock())과 실제 장바구니 저장 사이에 다른 요청이 재고를 변경할 수 있습니다. 동시 요청이 많은 환경에서는 재고 초과 등록이 발생할 수 있습니다.현 단계에서는 장바구니 추가 시점의 검증이므로 실제 결제/주문 시점에서 최종 재고 차감과 검증이 이루어진다면 큰 문제는 아닙니다. 다만, 향후 트래픽이 증가하면 비관적 락(
SELECT ... FOR UPDATE) 또는 낙관적 락(@Version)을 고려해 주세요.
- 사용자가 사이즈/색상을 변경할 때, 변경 후 조합이 동일 사용자의 다른 장바구니 항목과 중복될 수 있습니다. 예를 들어 같은 상품의 (S, 블랙)과 (M, 블랙)이 이미 장바구니에 있을 때, 전자를 (M, 블랙)으로 변경하면 중복 항목이 생깁니다. 이를 방지하고 같은 상품의 동일 사이즈와 색깔으로 변경할 경우 바꾼 장바구니를 삭제 후 하나로 합치는 작업을 하게됩니다.
🔍️ 작업 내용
장바구니 추가 시 검증 추가, 상품 옵션 조회 API 추가
✨ 상세 설명
🛠️ 추후 리팩토링 및 고도화 계획
📸 스크린샷 (선택)
상품별 옵션 조회 리스트

색상 or 사이즈 검증 로직 테스트

💬 리뷰 요구사항
Summary by CodeRabbit
새로운 기능
버그 수정