Skip to content

[Feature] (소비자) 장바구니 상품 옵션 수량 변경 API#719

Open
mono0801 wants to merge 4 commits into
devfrom
feature/customer-cart-option-quantity-update
Open

[Feature] (소비자) 장바구니 상품 옵션 수량 변경 API#719
mono0801 wants to merge 4 commits into
devfrom
feature/customer-cart-option-quantity-update

Conversation

@mono0801

@mono0801 mono0801 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

History

🚀 Major Changes & Explanations

  • 장바구니에 담긴 상품의 옵션 수량을 변경하는 API 구현

📷 Test Image

image image

💡 ETC

Summary by CodeRabbit

  • New Features

    • 장바구니 상품 옵션의 수량을 변경할 수 있는 기능이 추가되었습니다.
    • 변경 결과에 옵션 정보와 수량이 포함되어 반환됩니다.
  • Bug Fixes

    • 다른 회원의 장바구니 옵션은 조회/수정되지 않도록 검증이 강화되었습니다.
    • 수량 변경 시 재고 초과 요청에 대한 오류 처리가 추가되었습니다.
  • Tests

    • 수량 변경 API, 서비스, 저장소에 대한 성공/실패 시나리오 테스트가 추가되었습니다.

@mono0801 mono0801 self-assigned this Jun 29, 2026
@mono0801 mono0801 added feat New feature or request test Tags to use when testing labels Jun 29, 2026
@mono0801 mono0801 linked an issue Jun 29, 2026 that may be closed by this pull request
1 task
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2592fb1-d4d0-4761-abfc-7b6a11542abb

📥 Commits

Reviewing files that changed from the base of the PR and between b477726 and ed949b6.

📒 Files selected for processing (11)
  • src/main/java/com/bbangle/bbangle/cart/customer/controller/CustomerCartController.java
  • src/main/java/com/bbangle/bbangle/cart/customer/controller/dto/CartRequest.java
  • src/main/java/com/bbangle/bbangle/cart/customer/controller/dto/CartResponse.java
  • src/main/java/com/bbangle/bbangle/cart/customer/controller/swagger/CustomerCartApi.java
  • src/main/java/com/bbangle/bbangle/cart/customer/facade/CustomerCartFacade.java
  • src/main/java/com/bbangle/bbangle/cart/customer/service/CustomerCartOptionService.java
  • src/main/java/com/bbangle/bbangle/cart/repository/CartOptionRepository.java
  • src/test/java/com/bbangle/bbangle/cart/customer/controller/CustomerCartControllerTest.java
  • src/test/java/com/bbangle/bbangle/cart/customer/facade/CustomerCartFacadeIntegrationTest.java
  • src/test/java/com/bbangle/bbangle/cart/customer/facade/CustomerCartFacadeUnitTest.java
  • src/test/java/com/bbangle/bbangle/cart/repository/CartOptionRepositoryTest.java

Walkthrough

장바구니 옵션 수량 변경을 위한 PATCH /carts/options/{cartOptionId} 엔드포인트를 추가합니다. 리포지토리에 회원 소유 검증 JPQL 쿼리, 서비스 조회 메서드, 파사드 비즈니스 로직, 요청/응답 DTO, Swagger 문서화, 컨트롤러 구현이 함께 추가되며 단위·통합·컨트롤러 테스트도 포함됩니다.

Changes

장바구니 옵션 수량 변경 기능

Layer / File(s) Summary
요청/응답 DTO 및 리포지토리 쿼리
...dto/CartRequest.java, ...dto/CartResponse.java, ...repository/CartOptionRepository.java
UpdateCartOptionRequest(수량 @Min(1)/@max(999))와 UpdateCartOptionResponse(cartOptionId/optionId/optionName/quantity) DTO를 정의하고, CartOptionRepositoryco.option을 join fetch하며 회원 소유를 검증하는 findByIdAndMemberId JPQL 메서드를 추가합니다.
서비스 조회 및 파사드 비즈니스 로직
...service/CustomerCartOptionService.java, ...facade/CustomerCartFacade.java
CustomerCartOptionServicefindByIdAndMemberId(미존재 시 NOT_FOUND_CART_OPTION 예외) 메서드를 추가하고, CustomerCartFacadeupdateQuantity(옵션 조회 → 재고 검증 → 수량 업데이트 → 응답 반환)를 구현합니다. deleteCartOptions 메서드는 파일 내 하단으로 재배치됩니다.
컨트롤러 및 Swagger 엔드포인트
...controller/CustomerCartController.java, ...swagger/CustomerCartApi.java
CustomerCartControllerPATCH /options/{cartOptionId} 엔드포인트를 추가하고, CustomerCartApi Swagger 인터페이스에 @Operation 메타데이터와 함께 동일 시그니처를 정의합니다.
리포지토리·파사드·컨트롤러 테스트
...repository/CartOptionRepositoryTest.java, ...facade/CustomerCartFacadeUnitTest.java, ...facade/CustomerCartFacadeIntegrationTest.java, ...controller/CustomerCartControllerTest.java
findByIdAndMemberId 쿼리(성공/다른회원/미존재), updateQuantity 단위·통합(성공/재고초과/다른회원), updateCartOption 컨트롤러(성공/404) 케이스를 각각 검증하는 테스트를 추가합니다.

Sequence Diagram(s)

sequenceDiagram
  participant Client as 클라이언트
  participant Controller as CustomerCartController
  participant Facade as CustomerCartFacade
  participant Service as CustomerCartOptionService
  participant Repo as CartOptionRepository

  Client->>Controller: PATCH /carts/options/{cartOptionId} (quantity)
  Controller->>Facade: updateQuantity(memberId, cartOptionId, request)
  Facade->>Service: findByIdAndMemberId(memberId, cartOptionId)
  Service->>Repo: findByIdAndMemberId(cartOptionId, memberId)
  Repo-->>Service: Optional<CartOption>
  Service-->>Facade: CartOption (없으면 NOT_FOUND_CART_OPTION 예외)
  Facade->>Facade: option.validateStock(quantity) (초과 시 INVALID_REQUEST_STOCK 예외)
  Facade->>Service: updateQuantity(cartOption, quantity)
  Facade-->>Controller: UpdateCartOptionResponse
  Controller-->>Client: SingleResult<UpdateCartOptionResponse>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • eco-dessert-platform/backend#701: CustomerCartFacadeCartOptionRepository를 중심으로 장바구니 옵션 관련 기능을 확장하는 동일 코드 영역의 변경입니다.
  • eco-dessert-platform/backend#710: deleteCartOptions 로직과 BbangleErrorCode.NOT_FOUND_CART_OPTION을 공유하는 동일 클래스 내 연속 변경입니다.
  • eco-dessert-platform/backend#713: CustomerCartController/CustomerCartFacade 확장 및 CartOptionRepository 조회 메서드 추가라는 동일 코드 경로에 해당합니다.

Suggested reviewers

  • exjuu
  • CUCU7103
  • kimjongsoo97
  • kmindev

Poem

🐇 토끼가 장바구니를 들고 달려가네,
수량을 바꾸려 PATCH 요청을 보내네.
재고 검증, 회원 확인, 예외도 꼼꼼히~
updateQuantity 한 번에 척척 처리!
🥕 당근 999개까지도 문제없어요.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 소비자용 장바구니 옵션 수량 변경 API 추가라는 주요 변경점을 정확하고 간결하게 요약합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/customer-cart-option-quantity-update

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.

@mono0801 mono0801 marked this pull request as ready for review June 29, 2026 13:04
) {}
}

public record UpdateCartOptionRequest(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FE에서 +, - 버튼 누를 때 마다 API를 콜하도록 설계하셨을까요?
아니면 FE에서 주기적으로 배치성으로 option 수량을 보내도록 생각하시나요?

버튼마다 API 콜을 한다면, 행위를(increase / decrease) 받는 게 좋을 것 같습니다! (수량을 받으면 순서가 꼬이는 케이스가 있을 수 있을 것 같습니다.)

배치성이라면 장바구니 현행 상태를 전체로 받을 수 있도록 설계하는 게 좋을 것 같습니다.

개인적으로 배치성으로 가는 게 부하를 줄이는 데 좋을 방향인 것 같습니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

버튼에 따라서 +,- 1씩 증감하는 API를 따로 만드는 것보단
최종 수량을 FE에서 보내고 하나의 API로 처리하는게 간편할 것 같아서
직접 수량을 통해 변경되도록 구현했습니다.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+, - 버튼마다 요청을 보내는 게 아니라 최종 상태일 때 한 번만 호출하는 것으로 이해하면 되는거죠?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

기획 상으로는 +, - 버튼으로도 변경이 가능하고 직접 수량을 입력하여 변경할 수 있기 때문에,
+, - 버튼을 누르면 FE에서 1씩 증감한 값을 request에 담아서 보내도록 생각하고 있습니다.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fe 에서 연속 클릭은 못하도록 막아야겠네요
연타시 순서뒤바뀜 이슈가 있을 것 같네요

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

그러면 1씩 증감하는 별도의 API를 만들까요?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

말씀하신 +1, -1 API 분리도 정합성 면에서는 안전하지만, 기획에 있는 '수량 직접 입력' 기능까지 고려하면 결국 두 가지 스타일의 API를 모두 관리해야 하는 부담이 생길 것 같습니다.

FE와 협의하여 특정 주기나 이벤트(예: 장바구니 화면 이탈 시, 혹은 수량 변경 후 n초간 입력이 없을 때)마다 현재 장바구니의 현행 상태를 배치(Batch) 형태로 일괄 요청하는 방식이 가장 좋지 않을까요?

그렇기 위해서는 optionId 별로 현재 수량을 모두 받는 API로 개발이 되면 좋을 것 같습니다!

다른 의견 있으시면 편하게 말씀해주세요!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

그럼 현재 API 1개로 유지하고 FE에서 너무 잦은 API 호출이 발생하지 않도록 조치하자는 말씀이신가요?

@kmindev kmindev Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

optionId 목록과 optionId 별로 수량을 body로 받는 형태로 생각하긴 했습니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

그렇게 되면 사용자 입장에서 UI를 통해 수량 변경을 했지만 아직 API 호출을 하지 않았기 때문에
새로고침을 할 경우 이전 장바구니 상태로 되돌아가는 상황이 발생할 것 같습니다.

@kmindev kmindev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

현호님 코멘트 남겼습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature or request test Tags to use when testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] (소비자) 장바구니 상품 옵션 수량 변경

2 participants