Skip to content

Commit

Permalink
Feat: Order 도메인 객체 구현
Browse files Browse the repository at this point in the history
- totalPrice를 계산하는 calculateTotalPrice() 구현
- deliveryPrice를 계산하는 calculateDeliveryPrice() 구현
  • Loading branch information
Louie-03 committed Apr 26, 2022
1 parent c20b925 commit 0fdbb79
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions BE/src/main/java/sidedish/com/domain/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package sidedish.com.domain;

import lombok.Getter;

@Getter
public class Order {
private final Product product;
private final long count;
private final long totalPrice;
private final long deliveryPrice;

public Order(Product product, long count) {
this.product = product;
this.count = count;
this.totalPrice = calculateTotalPrice();
this.deliveryPrice = calculateDeliveryPrice();
}

private long calculateTotalPrice() {
return count * product.getFixedPrice();
}

private long calculateDeliveryPrice() {
if (totalPrice >= product.getDeliveryPolicy().getFreeDeliveryOverAmount()) {
return 0;
}
return product.getDeliveryPolicy().getDeliveryCharge();
}
}

0 comments on commit 0fdbb79

Please sign in to comment.