Skip to content

[Fix] 장바구니 추가 시 검증 추가, 상품 옵션 조회 API 추가#96

Merged
kangcheolung merged 3 commits intodevelopfrom
feature/95
Feb 7, 2026
Merged

[Fix] 장바구니 추가 시 검증 추가, 상품 옵션 조회 API 추가#96
kangcheolung merged 3 commits intodevelopfrom
feature/95

Conversation

@kangcheolung
Copy link
Copy Markdown
Member

@kangcheolung kangcheolung commented Feb 7, 2026

🔍️ 작업 내용

  • Closes #
    장바구니 추가 시 검증 추가, 상품 옵션 조회 API 추가

✨ 상세 설명

  • 장바구니 추가시 없는 색상과 사이즈가 있을시에도 추가가 된다는 프론트의 수정 요청으로 인해서 검증을 추가하였고, 추가적으로 재고 관련 검증도 추가했습니다.
  • 상품 상세 화면에서 해당 상품의 사이즈 or 색상 등의 옵션 리스트를 조회하는 기능이 필요하다는 프론트 요청으로 상품별 옵션 목록 조회 기능을 추가했습니다.

🛠️ 추후 리팩토링 및 고도화 계획

📸 스크린샷 (선택)

상품별 옵션 조회 리스트
image

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

💬 리뷰 요구사항

Summary by CodeRabbit

  • 새로운 기능

    • 상품 옵션(색상/사이즈) 전체 조회 API 추가 — 제품별 선택 가능한 옵션을 조회할 수 있습니다.
  • 버그 수정

    • 장바구니 추가/수정 시 옵션별 재고 검증 강화 — 재고 부족으로 인한 주문 방지
    • 옵션 변경 시 중복 항목 병합 및 수량 검증 적용
    • 재고/옵션 관련 명확한 오류 코드·메시지 추가 (옵션 미존재, 재고부족)

kangcheolung and others added 2 commits February 7, 2026 17:50
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

CartService에 상품 옵션(ProductOption) 조회 및 재고 검증 로직을 추가하고, ProductService/ProductController에 상품 옵션 조회 API를 도입하며 관련 오류 코드(PRODUCT_OPTION_NOT_FOUND, OUT_OF_STOCK)를 추가합니다.

Changes

Cohort / File(s) Summary
Cart Service 재고/옵션 처리
src/main/java/com/ongil/backend/domain/cart/service/CartService.java
ProductOptionRepository/ProductOption 의존성 추가. addCart에서 상품옵션 존재 검증 및 재고(기존 수량 포함) 검증 후 추가/수정 로직 적용. updateCart에서 옵션 및 수량 변경 시 재고 검증, 동일 옵션 병합(중복체크 + 병합/삭제) 로직 추가.
Product Options API & 변환기 가시성
src/main/java/com/ongil/backend/domain/product/controller/ProductController.java, src/main/java/com/ongil/backend/domain/product/service/ProductService.java, src/main/java/com/ongil/backend/domain/product/converter/ProductConverter.java
ProductController에 GET /api/products/{productId}/options 엔드포인트 추가. ProductService에 getProductOptions(productId) 추가(상품 존재 검증 후 옵션 리스트 반환). ProductConverter.convertOptions() 접근 제어자를 private→public으로 변경.
에러 코드 확장
src/main/java/com/ongil/backend/global/common/exception/ErrorCode.java
PRODUCT_OPTION_NOT_FOUNDOUT_OF_STOCK 에러 코드 추가.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Suggested labels

🐞 Fix

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 핵심을 명확하게 반영합니다. 장바구니 추가 시 검증 추가와 상품 옵션 조회 API 추가라는 두 가지 주요 변경사항을 정확하게 요약하고 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/95

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, 블랙)으로 변경하면 중복 항목이 생깁니다. 이를 방지하고 같은 상품의 동일 사이즈와 색깔으로 변경할 경우 바꾼 장바구니를 삭제 후 하나로 합치는 작업을 하게됩니다.
@kangcheolung kangcheolung merged commit 1a30850 into develop Feb 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant