-
Notifications
You must be signed in to change notification settings - Fork 2
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
[OrderService
의 placeOrder
] 재고 관련 로직 추가
#55
[OrderService
의 placeOrder
] 재고 관련 로직 추가
#55
Conversation
c387fc9
to
6af352a
Compare
6af352a
to
6db71a8
Compare
placeOrder
재고 관련 로직 추가OrderService
의 placeOrder
] 재고 관련 로직 추가
src/main/java/com/hcommerce/heecommerce/order/OrderService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/hcommerce/heecommerce/order/OrderService.java
Outdated
Show resolved
Hide resolved
int currentInventory = inventoryCommandRepository.decreaseByAmount(key, realOrderQuantity); // TODO : 결제가 실패하여 재고량 다시 원상복귀해야할 때도, 분산락 걸어줘야 되나? | ||
|
||
if(currentInventory == 0) { | ||
// TODO : [품절 처리] Redis에 저장된 dealproducts 목록에서 딜 상품 상태 오픈 -> 품절로 변경 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dealproducts의 상품 상태를 특정 사용자의 placeOrder에서 진행하는 것이 좋은 workflow일까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일단 해당 로직은 삭제시켰는데, 제가 생각한 방법는 2가지 입니다. @f-lab-TJ 의견은 어떠신가요?
방법 1. DealService
에서 dealproducts의 상품 상태를 변경하는 로직을 구현하고, 여기서 가져다 사용하는 방법
방법 2. 특정 시간(예: 10초 마다, 트리팩 높은 초기 10분은 그보다 짧게?) dealproducts의 상품 상태를 변경하는 AWS CloudWatch Events + AWS Lambda 만드는 방법
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상품의 상태가 currentInventory에 의해 결정된다면, 상품의 상태를 따로 표현해야 할 이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상품의 상태가 currentInventory의해서만 결정되는게 아니라 오픈 시간, 마감 시간 등 다른 필드에 의해서도 결정되어서 상품의 상태를 따로 표현했습니다. 재고량, 오픈 시간, 마감 시간 등을 프론트에 내려주고, 그 숫자를 기반으로 프론트에서 상태를 표현하는 방법도 한가지 방법일 수 있겠지만, 백앤드에서 최대한 로직을 계산해서 프론트에는 값만 내려주는 상황을 가정했습니다. @f-lab-TJ 은 어떠신가요?
} | ||
|
||
// 2. 재고량 감소 | ||
int currentInventory = inventoryCommandRepository.decreaseByAmount(key, realOrderQuantity); // TODO : 결제가 실패하여 재고량 다시 원상복귀해야할 때도, 분산락 걸어줘야 되나? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 함수가 호출 된 이후에 주문이 성공한 경우를 제외하고는 반드시 Amount를 복구시켜주어야 합니다. 그런 경우 어떤식으로 코드를 작성하면 좋을까요?
해당 함수에 의해 품절 처리가 되었으나, 결제가 완료되지 않거나 여러가지 이유로 다시 재고가 발생하는 케이스가 있습니다. 어떻게 처리하면 좋을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 함수가 호출 된 이후에 주문이 성공한 경우를 제외하고는 반드시 Amount를 복구시켜주어야 합니다. 그런 경우 어떤식으로 코드를 작성하면 좋을까요?
- 일단 결제가 실패하는 상황만 가정하고, 그때 로직은 다시 재고량을 올려주도록 구현했습니다.
해당 함수에 의해 품절 처리가 되었으나, 결제가 완료되지 않거나 여러가지 이유로 다시 재고가 발생하는 케이스가 있습니다. 어떻게 처리하면 좋을까요?
- 결제가 완료되지 않거나 여러가지 이유로 다시 재고가 발생하는 상황이 발생하면, 첫번째 질문에 대한 답변처럼 다시 재고량을 올려주는 로직을 추가할 것 같습니다. 추가로, DB에 저장된게 있다면 rollback 처리를 할 것 같고, 이를 위해서 @transactional 을 활용할 것 같습니다.
ab4bb68
to
37a9859
Compare
|
||
// 2. 재고량 감소 | ||
String key = "dealProductInventory:"+dealProductUuid.toString(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
�코드와 코드 사이에 언제 뉴라인을 넣고, 언제 넣지 않나요? 일반적으로 뉴라인은 강제되는 컨벤션은 아니지만, 코드 읽기에 도움을 주기도 방해를 하기도 합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아래와 같이 함수가 간단한 거나 메서드 바로 밑의 코드를 제외하고는 모두 뉴라인을 넣어주려고 합니다.
private void rollbackReducedInventory(String key, int amount) {
inventoryCommandRepository.increaseByAmount(key, amount);
}
37a9859
to
c9b4cba
Compare
c9b4cba
to
3297982
Compare
What
Comment