Skip to content

Commit

Permalink
Feat: Product 클래스에 재고 수량 차감 로직 구현
Browse files Browse the repository at this point in the history
- 만약 주문 개수보다 재고 수량이 부족하다면 NotEnoughStockQuantityException이 발생한다.
  • Loading branch information
Louie-03 committed Apr 26, 2022
1 parent 0fdbb79 commit 6543cb6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion BE/src/main/java/sidedish/com/domain/Product.java
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import lombok.Getter;
import sidedish.com.exception.NotEnoughStockQuantityException;

@Getter
public class Product {
Expand All @@ -16,7 +17,7 @@ public class Product {
private final String description;
private final long fixedPrice;
private final long originalPrice;
private final long stockQuantity;
private long stockQuantity;
private final String mealCategory;
private final String bestCategory;
private final long mileage;
Expand All @@ -25,6 +26,9 @@ public Product(Long id, DiscountPolicy discountPolicy,
DeliveryPolicy deliveryPolicy, List<Image> images, String productName,
String description, long originalPrice, long stockQuantity, String mealCategory,
String bestCategory) {
if (stockQuantity < 0) {
throw new NotEnoughStockQuantityException("재고가 충분하지 않습니다");
}
this.id = id;
this.discountPolicy = discountPolicy;
this.deliveryPolicy = deliveryPolicy;
Expand All @@ -46,4 +50,11 @@ private long calculateMileage() {
private long calculateFixedPrice() {
return discountPolicy.calculateFixedPrice(originalPrice);
}

public void minusStockQuantity(long count) {
if (count > stockQuantity) {
throw new NotEnoughStockQuantityException("재고가 충분하지 않습니다");
}
stockQuantity -= count;
}
}
@@ -0,0 +1,12 @@
package sidedish.com.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.BAD_REQUEST)
public class NotEnoughStockQuantityException extends RuntimeException {

public NotEnoughStockQuantityException(String message) {
super(message);
}
}

0 comments on commit 6543cb6

Please sign in to comment.