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] 장바구니에 현재까지 담은 음식 상품의 금액을 볼 수 있는 기능 추가 #70

Merged
20 changes: 19 additions & 1 deletion src/main/java/camp/woowak/lab/cart/domain/Cart.java
june-777 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ public class Cart {
* @param customerId 장바구니 소유주의 ID값입니다.
*/
public Cart(String customerId) {
this(customerId, new LinkedList<>());
}

/**
* 해당 Domain을 사용하는 같은 패키지내의 클래스, 혹은 자식 클래스는 List를 커스텀할 수 있습니다.
*
* @param customerId 장바구니 소유주의 ID값입니다.
* @param menuList 장바구니에 사용될 List입니다.
*/
protected Cart(String customerId, List<Menu> menuList) {
this.customerId = customerId;
this.menuList = new LinkedList<>();
this.menuList = menuList;
}

public void addMenu(Menu menu) {
Expand All @@ -36,6 +46,14 @@ public void addMenu(Menu menu) {
this.menuList.add(menu);
}

public long totalPrice() {
return this.menuList.stream()
.map(Menu::getPrice)
.mapToLong(Long::valueOf)
.boxed()
.reduce(0L, Long::sum);
}

private void validateStoreOpenTime(Store store) {
if (!store.isOpen()) {
StoreTime storeTime = store.getStoreTime();
Expand Down