[volume-4] 쿠폰 추가, 동시성 제어 적용#143
[volume-4] 쿠폰 추가, 동시성 제어 적용#143hyejin0810 wants to merge 19 commits intoLoopers-dev-lab:hyejin0810from
Conversation
- 장바구니 최대 100개 제한 제거 - likes_count 동시성: @Version 낙관적 락 명시 (시퀀스 다이어그램, 클래스 다이어그램, 요구사항) - 주문번호 생성 전략: UUID 기반 (ORD-yyyyMMdd-{UUID 앞 8자리}) 명시 - 주문 취소 트랜잭션: @transactional 원자적 처리 범위 명시 - 물리적 FK: ORDERS→USERS, ORDER_ITEMS→ORDERS 구간 DDL FK 제약 명시 - OrderFacade 추가: OrderService + CartService 조율로 관심사 분리 - CartService 추가: 장바구니 관리 책임 분리 - OrderService.generateOrderNumber() 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- 장바구니(Cart) 도메인 전체 제거 (요구사항, 시퀀스, 클래스, ERD) - User에 balance 필드 추가 (USERS 테이블 포함) - 주문 생성 시퀀스: 잔액 확인 → 잔액 차감 흐름 추가 - 주문 취소 시퀀스: 잔액 복구 단계 추가 (UserRepo 참여자 추가) - 기능 요구사항: 잔액 조회, 잔액 확인/차감/복구 항목 추가 - 시나리오 3 → 상품 주문으로 변경 (장바구니 시나리오 삭제) - 핵심 제약: 잔액 부족 시 주문 실패 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- User: balance 추가, deductBalance/restoreBalance, authenticate() - Brand: 등록/조회/삭제 CRUD - Product: @Version 낙관적 락, decreaseStock/increaseStock, likesCount - Like: 중복 방지(CONFLICT), 취소(NOT_FOUND), Product.likesCount 연동 - Order/OrderItem: UUID 주문번호, PENDING/CONFIRMED/CANCELLED 상태 관리 - OrderFacade: 재고 차감 + 잔액 차감 단일 트랜잭션, 취소 시 원복 - 각 도메인 단위 테스트 (LikeTest, LikeServiceTest, OrderTest, OrderServiceTest 등) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- BrandFacade.deleteBrand에 @transactional 추가 (연쇄 삭제 원자성 보장) - OrderFacade.cancelOrder에 주문 소유자 검증 추가 (타인 주문 취소 시 NOT_FOUND) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- cancelOrder(Long id) → cancelOrder(Order order)로 변경하여 중복 조회 제거 - Facade에서 조회한 Order를 직접 전달하도록 수정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- UserServiceTest: isNotNull() 중복 제거 (isEqualTo로 충분) - OrderTest: 테스트 이름과 무관한 필드 검증 제거 (status만 검증) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- UserFacade 생성: getMyInfo 유스케이스를 application 레이어로 이동 - UserService에서 getMyInfo 제거 및 UserInfo import 삭제 (domain → application 역방향 의존 해소) - UserV1Controller가 getMyInfo를 UserFacade를 통해 호출하도록 수정 - UserFacadeTest 추가, UserServiceTest의 GetMyInfo 테스트 이동 - UserV1ControllerStandaloneTest를 UserFacade mock 기반으로 수정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Service 레이어(User/Brand/Product/Like/Order/Member)의 @transactional 전부 제거 - BrandFacade: register(@transactional), getBrand/getBrands(@transactional readOnly) 추가 - ProductFacade: 모든 메서드에 @transactional 추가 - 트랜잭션 경계를 유스케이스 단위인 Facade로 일원화 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- User/Brand/Product/Like/Order/MemberService 메서드에 @transactional 복원 - 쓰기 메서드: @transactional, 읽기 메서드: @transactional(readOnly = true) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
상품 ID 오름차순 정렬 후 재고 차감/복구 처리 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
쿠폰 사용/복구 시 ObjectOptimisticLockingFailureException을 Facade에서 잡아 CoreException(CONFLICT)으로 변환하여 클라이언트에 의미있는 에러 메시지 반환 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📌 Summary
🧭 Context & Decision
변경 사항
쿠폰 도메인 신규 구현
동시성 제어
재고: UPDATE ... WHERE stock >= quantity 방식을 통해 DB 레벨에서 원자적 차감을 수행하여 초과 차감을 방지.
쿠폰 사용: 충돌 가능성이 낮은 비즈니스 특성을 고려하여 @Version을 활용한 낙관적 락 사용.
좋아요 수: 별도의 락 없이 아토믹 업데이트를 사용하여 동시성 경쟁 상황에서도 카운트 보장.
좋아요 중복: 애플리케이션의 유효성 검사와 DB Unique Constraint를 결합하여 중복 데이터 생성을 완벽히 차단.
주문-쿠폰 통합
Admin / 대고객 API (8개 추가)
/api-admin/v1/coupons/api-admin/v1/coupons/api-admin/v1/coupons/{couponId}/api-admin/v1/coupons/{couponId}/api-admin/v1/coupons/{couponId}/api-admin/v1/coupons/{couponId}/issues/api/v1/coupons/{couponId}/issue/api/v1/users/me/coupons기존 주문 API에 couponId (요청), originalAmount / discountAmount / userCouponId (응답) 필드 추가.
테스트