Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 쿠폰 API 구현 - 비관적 락, 낙관적 락 #21

Closed
wants to merge 11 commits into from

Conversation

tnals2384
Copy link
Collaborator

📌 과제 설명

  • 쿠폰 생성 (추후 관리자용으로 변경 필요합니다)
  • 내 쿠폰 조회
  • 쿠폰 발급 (비관적 락)
  • 쿠폰 발급 (낙관적 락)

쿠폰 발급 API Controller는 따로 구현하지 않았습니다.

✅ PR 포인트 & 궁금한 점

낙관적 락의 경우 MySQL 테스트할 때 실패합니다. MySQL 자체 s-lock, x-lock 규칙 때문으로 보입니다.
자세한 내용은 노션에 적어두었습니다~
낙관적 락 이용 시 DeadLock 발생

}
);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

주석이 친절하네용..!! bb

//then
assertEquals(100, coupon.getAmount());
assertEquals(FIVE, coupon.getDiscountRate());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

DisplayName 을 친절하게 작성해주신 것 같습니당 bb

Copy link
Collaborator

@AnTaeho AnTaeho left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!
@DisplayName 저도 자세하게 짤껄 반성하게 됩니다...!
테스트 케이스도 자세하게 잘 작성하신 것 같아요

Comment on lines 32 to 35
@PostMapping
public ResponseEntity<CouponIdResponse> createCoupon(@RequestBody @Valid CouponCreateRequest couponCreateRequest) {
return ResponseEntity.status(HttpStatus.CREATED).body(couponCommandService.createCoupon(couponCreateRequest));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

P 4~5

Suggested change
@PostMapping
public ResponseEntity<CouponIdResponse> createCoupon(@RequestBody @Valid CouponCreateRequest couponCreateRequest) {
return ResponseEntity.status(HttpStatus.CREATED).body(couponCommandService.createCoupon(couponCreateRequest));
}
@PostMapping
public ResponseEntity<CouponIdResponse> createCoupon(
@RequestBody @Valid CouponCreateRequest couponCreateRequest
) {
return ResponseEntity
.status(HttpStatus.CREATED)
.body(couponCommandService.createCoupon(couponCreateRequest));
}

저도 이렇게 줄바꿈을 해주면 좋을 것 같습니다!

Comment on lines 39 to 41
if(coupon.getAmount() <= 0) {
throw new IllegalArgumentException(COUPON_OUT_OF_STOCK);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

P3.5

Suggested change
if(coupon.getAmount() <= 0) {
throw new IllegalArgumentException(COUPON_OUT_OF_STOCK);
}
if(coupon.noStock()) {
throw new IllegalArgumentException(COUPON_OUT_OF_STOCK);
}

개인적으론 이렇게 coupon 객체에 재고가 없는지 물어보거나
아니면 재고를 감소 시킬때 체크해주는 것이 더 객체지향적이라고 생각합니다!

https://skyblue300a.tistory.com/18

Copy link
Collaborator Author

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 선착순 쿠폰 발급 API - 낙관적 락, 비관적 락 구현
3 participants