From f600f86b7d93472401e970d98e0bff9490506614 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 15:50:07 +0900 Subject: [PATCH 01/50] =?UTF-8?q?style(Product):=20=EA=B0=9C=ED=96=89=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/kitchenpos/products/tobe/domain/Product.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/kitchenpos/products/tobe/domain/Product.java b/src/main/java/kitchenpos/products/tobe/domain/Product.java index c1bab961d..5ed07836b 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Product.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Product.java @@ -2,7 +2,6 @@ public class Product { private ProductPrice price; - private DisplayedName name; public Product(final ProductPrice price, final DisplayedName name) { From d57c1cdd29d70057442aec66646fa1d75783a490 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 16:02:00 +0900 Subject: [PATCH 02/50] =?UTF-8?q?feat(DisplayedName):=20=EC=83=81=ED=92=88?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20null,=20empty=20=EB=B0=A9=EC=96=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../products/tobe/domain/DisplayedName.java | 4 ++++ .../products/tobe/domain/DisplayedNameTest.java | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java index 3fa934c9e..81e018396 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java @@ -3,11 +3,15 @@ import java.util.Objects; public class DisplayedName { + private static final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; private final String name; public DisplayedName(final String name, final Profanity profanity) { + if (null == name || name.isBlank()) { + throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); + } if (profanity.isContains(name)) { throw new IllegalArgumentException(CONTAIN_PROFANITY_MESSAGE); } diff --git a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java index d00fdd079..d1ffaa827 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java @@ -2,6 +2,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -10,6 +12,17 @@ - [x] 상품의 이름에는 비속어가 포함될 수 없다. */ class DisplayedNameTest { + @DisplayName("상품 이름은 비어있을 수 없다.") + @NullAndEmptySource + @ParameterizedTest + void emptyName(final String name) { + final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; + + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(EMPTY_NAME_MESSAGE); + } + @DisplayName("상품 이름에 비속어가 포함될 수 없다.") @Test void registerWithProfanity() { From 7a0bcf6f2f6caa95241ea558419aac2a6fb942b8 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 16:05:42 +0900 Subject: [PATCH 03/50] =?UTF-8?q?refactor(ProductPrice):=20Bigdecimal=20?= =?UTF-8?q?=EB=B9=84=EA=B5=90=EA=B0=92=20=EC=83=81=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kitchenpos/products/tobe/domain/ProductPrice.java | 3 +-- .../kitchenpos/products/tobe/domain/DisplayedNameTest.java | 4 ---- .../kitchenpos/products/tobe/domain/ProductPriceTest.java | 4 ---- .../java/kitchenpos/products/tobe/domain/ProductTest.java | 6 ------ 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java index f49177c06..6ae291544 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java +++ b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java @@ -4,13 +4,12 @@ import java.util.Objects; public class ProductPrice { - private static final int MIN_PRICE = 0; private static final String INVALID_PRICE_MESSAGE = "상품 가격은 0보다 크거다 같아야 합니다."; private final BigDecimal price; public ProductPrice(final BigDecimal price) { - if (price.compareTo(BigDecimal.ZERO) < MIN_PRICE) { + if (price.compareTo(BigDecimal.ZERO) < 0) { throw new IllegalArgumentException(INVALID_PRICE_MESSAGE); } this.price = price; diff --git a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java index d1ffaa827..88cc13d53 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java @@ -7,10 +7,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; -/* -- [x] 상품의 이름이 올바르지 않으면 등록할 수 없다. -- [x] 상품의 이름에는 비속어가 포함될 수 없다. -*/ class DisplayedNameTest { @DisplayName("상품 이름은 비어있을 수 없다.") @NullAndEmptySource diff --git a/src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java b/src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java index b3109e7de..debc04671 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java @@ -7,10 +7,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; -/* -- [x] 상품의 가격이 올바르지 않으면 등록할 수 없다. -- [x] 상품의 가격은 0원 이상이어야 한다. - */ class ProductPriceTest { @DisplayName("상품의 가격은 0보다 크거나 같아야 한다.") @Test diff --git a/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java b/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java index a9f269018..d0bc8a319 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java @@ -7,12 +7,6 @@ import static org.assertj.core.api.Assertions.assertThatCode; -/* -- [x] 상품을 등록할 수 있다. -- [x] 상품의 가격을 변경할 수 있다. -- 상품의 가격이 변경될 때 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 크면 메뉴가 숨겨진다. -- 상품의 목록을 조회할 수 있다. - */ class ProductTest { @DisplayName("상품을 등록할 수 있다.") @Test From d4d0c16bc6b96608162cc9a66eb9e5733167ba19 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 16:48:40 +0900 Subject: [PATCH 04/50] =?UTF-8?q?feat(MenuPrice):=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=EC=9D=80=200=EB=B3=B4=EB=8B=A4=20=ED=81=AC?= =?UTF-8?q?=EA=B1=B0=EB=82=98=20=EA=B0=99=EC=95=84=EC=95=BC=20=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/Menu.java | 4 +++ .../menus/tobe/domain/MenuPrice.java | 30 +++++++++++++++++++ .../menus/tobe/domain/MenuPriceTest.java | 25 ++++++++++++++++ .../menus/tobe/domain/MenuTest.java | 29 ++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/Menu.java create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java create mode 100644 src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java create mode 100644 src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java new file mode 100644 index 000000000..84b0cb56d --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -0,0 +1,4 @@ +package kitchenpos.menus.tobe.domain; + +public class Menu { +} diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java new file mode 100644 index 000000000..82535e140 --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java @@ -0,0 +1,30 @@ +package kitchenpos.menus.tobe.domain; + +import java.math.BigDecimal; +import java.util.Objects; + +public class MenuPrice { + private static final String INVALID_PRICE_MESSAGE = "메뉴 가격은 0보다 크거다 같아야 합니다."; + + private final BigDecimal price; + + public MenuPrice(final BigDecimal price) { + if (price.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException(INVALID_PRICE_MESSAGE); + } + this.price = price; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (null == o || getClass() != o.getClass()) return false; + final MenuPrice menuPrice = (MenuPrice) o; + return price == null ? menuPrice.price == null : price.compareTo(menuPrice.price) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(price); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java new file mode 100644 index 000000000..6f865d52d --- /dev/null +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java @@ -0,0 +1,25 @@ +package kitchenpos.menus.tobe.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/* +- [x] 메뉴의 가격은 0보다 크거나 같아야 한다. +- 메뉴의 가격이 올바르지 않으면 등록할 수 없다. (Null, Empty) + */ +class MenuPriceTest { + @DisplayName("메뉴의 가격은 0보다 크거나 같아야 한다.") + @Test + void registerWithLessThanZero() { + final String INVALID_PRICE_MESSAGE = "메뉴 가격은 0보다 크거다 같아야 합니다."; + final BigDecimal price = BigDecimal.valueOf(-1L); + + assertThatThrownBy(() -> new MenuPrice(price)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(INVALID_PRICE_MESSAGE); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java new file mode 100644 index 000000000..9dd03c6d2 --- /dev/null +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -0,0 +1,29 @@ +package kitchenpos.menus.tobe.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/* +- 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. +- 메뉴는 특정 메뉴 그룹에 속해야 한다. +- 메뉴의 이름이 올바르지 않으면 등록할 수 없다. + - 메뉴의 이름에는 비속어가 포함될 수 없다. +- 메뉴의 가격을 변경할 수 있다. +- 메뉴의 가격이 올바르지 않으면 변경할 수 없다. + - 메뉴의 가격은 0원 이상이어야 한다. +- 메뉴에 속한 상품의 수량은 0 이상이어야 한다. +- 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. +- 상품이 없으면 등록할 수 없다. +- 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. +- 메뉴를 노출할 수 있다. +- 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다. +- 메뉴를 숨길 수 있다. +- 메뉴의 목록을 조회할 수 있다. + */ +class MenuTest { + @DisplayName("메뉴를 생성할 수 있다.") + @Test + void construct() { + Menu menu = new Menu(); + } +} From 17b537a98863deb47ca42b1139a6e1368fcfed7b Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 16:55:15 +0900 Subject: [PATCH 05/50] =?UTF-8?q?feat(MenuPrice):=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=EC=9D=80=20=EB=B9=84=EC=96=B4=EC=9E=88?= =?UTF-8?q?=EC=9D=84=20=EC=88=98=20=EC=97=86=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/MenuPrice.java | 4 ++++ .../menus/tobe/domain/MenuPriceTest.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java index 82535e140..1a820bfab 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java @@ -4,11 +4,15 @@ import java.util.Objects; public class MenuPrice { + private static final String EMPTY_NAME_MESSAGE = "메뉴 가격은 비어있을 수 없습니다."; private static final String INVALID_PRICE_MESSAGE = "메뉴 가격은 0보다 크거다 같아야 합니다."; private final BigDecimal price; public MenuPrice(final BigDecimal price) { + if (null == price) { + throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); + } if (price.compareTo(BigDecimal.ZERO) < 0) { throw new IllegalArgumentException(INVALID_PRICE_MESSAGE); } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java index 6f865d52d..8ecd5915b 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java @@ -2,6 +2,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullSource; import java.math.BigDecimal; @@ -9,7 +11,7 @@ /* - [x] 메뉴의 가격은 0보다 크거나 같아야 한다. -- 메뉴의 가격이 올바르지 않으면 등록할 수 없다. (Null, Empty) +- [x] 메뉴의 가격이 올바르지 않으면 등록할 수 없다. (Null) */ class MenuPriceTest { @DisplayName("메뉴의 가격은 0보다 크거나 같아야 한다.") @@ -22,4 +24,15 @@ void registerWithLessThanZero() { .isInstanceOf(IllegalArgumentException.class) .hasMessage(INVALID_PRICE_MESSAGE); } + + @DisplayName("메뉴 가격은 비어있을 수 없다.") + @NullSource + @ParameterizedTest + void registerWithEmptyName(final BigDecimal price) { + final String EMPTY_NAME_MESSAGE = "메뉴 가격은 비어있을 수 없습니다."; + + assertThatThrownBy(() -> new MenuPrice(price)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(EMPTY_NAME_MESSAGE); + } } From e741cd7e0fea685afdf4e9222ac273a243736d2e Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 17:05:27 +0900 Subject: [PATCH 06/50] =?UTF-8?q?feat(DisplayedName):=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 메뉴 이름을 비어있을 수 없다. (Null, Empty) 2. 메뉴 이름에 비속어가 포함될 수 없다. --- .../menus/tobe/domain/DisplayedName.java | 35 ++++++++++++++++++ .../menus/tobe/domain/DisplayedNameTest.java | 36 +++++++++++++++++++ .../menus/tobe/domain/FakeProfanity.java | 14 ++++++++ .../menus/tobe/domain/MenuTest.java | 7 ++-- 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java create mode 100644 src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java create mode 100644 src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java new file mode 100644 index 000000000..c9113f511 --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java @@ -0,0 +1,35 @@ +package kitchenpos.menus.tobe.domain; + +import kitchenpos.products.tobe.domain.Profanity; + +import java.util.Objects; + +public class DisplayedName { + private static final String EMPTY_NAME_MESSAGE = "메뉴 이름은 비어있을 수 없습니다."; + private static final String CONTAIN_PROFANITY_MESSAGE = "메뉴 이름에 비속어가 포함될 수 없습니다."; + + private final String name; + + public DisplayedName(final String name, final Profanity profanity) { + if (null == name || name.isBlank()) { + throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); + } + if (profanity.isContains(name)) { + throw new IllegalArgumentException(CONTAIN_PROFANITY_MESSAGE); + } + this.name = name; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (null == o || getClass() != o.getClass()) return false; + final DisplayedName that = (DisplayedName) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java new file mode 100644 index 000000000..83431ae4f --- /dev/null +++ b/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java @@ -0,0 +1,36 @@ +package kitchenpos.menus.tobe.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/* +- [x] 메뉴의 이름이 올바르지 않으면 등록할 수 없다. (Null, Empty) +- [x] 메뉴의 이름에는 비속어가 포함될 수 없다. + */ +class DisplayedNameTest { + @DisplayName("메뉴 이름은 비어있을 수 없다.") + @NullAndEmptySource + @ParameterizedTest + void emptyName(final String name) { + final String EMPTY_NAME_MESSAGE = "메뉴 이름은 비어있을 수 없습니다."; + + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(EMPTY_NAME_MESSAGE); + } + + @DisplayName("메뉴 이름에 비속어가 포함될 수 없다.") + @Test + void registerWithProfanity() { + final String CONTAIN_PROFANITY_MESSAGE = "메뉴 이름에 비속어가 포함될 수 없습니다."; + final String name = "damn"; + + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(CONTAIN_PROFANITY_MESSAGE); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java b/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java new file mode 100644 index 000000000..fdcd180bd --- /dev/null +++ b/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java @@ -0,0 +1,14 @@ +package kitchenpos.menus.tobe.domain; + +import kitchenpos.products.tobe.domain.Profanity; + +import java.util.List; + +class FakeProfanity implements Profanity { + private final List values = List.of("damn"); + + @Override + public boolean isContains(final String name) { + return values.contains(name); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index 9dd03c6d2..ee93be033 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -4,14 +4,11 @@ import org.junit.jupiter.api.Test; /* -- 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. -- 메뉴는 특정 메뉴 그룹에 속해야 한다. -- 메뉴의 이름이 올바르지 않으면 등록할 수 없다. - - 메뉴의 이름에는 비속어가 포함될 수 없다. - 메뉴의 가격을 변경할 수 있다. - 메뉴의 가격이 올바르지 않으면 변경할 수 없다. - - 메뉴의 가격은 0원 이상이어야 한다. - 메뉴에 속한 상품의 수량은 0 이상이어야 한다. +- 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. +- 메뉴는 특정 메뉴 그룹에 속해야 한다. - 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. - 상품이 없으면 등록할 수 없다. - 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. From fce720abbc3a0b5e2c4eece3a94ce27c36254136 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 17:24:23 +0900 Subject: [PATCH 07/50] =?UTF-8?q?feat(Product):=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/Menu.java | 15 +++++++++++++++ .../kitchenpos/menus/tobe/domain/MenuTest.java | 18 ++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 84b0cb56d..257f155fd 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -1,4 +1,19 @@ package kitchenpos.menus.tobe.domain; public class Menu { + private MenuPrice price; + private DisplayedName name; + + public Menu(final MenuPrice price, final DisplayedName name) { + this.price = price; + this.name = name; + } + + public MenuPrice getPrice() { + return price; + } + + public void changePrice(final MenuPrice price) { + this.price = price; + } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index ee93be033..62e7b4a48 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -3,9 +3,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; + /* -- 메뉴의 가격을 변경할 수 있다. -- 메뉴의 가격이 올바르지 않으면 변경할 수 없다. +- [x] 메뉴의 가격을 변경할 수 있다. +- [x] 메뉴의 가격이 올바르지 않으면 변경할 수 없다. - 메뉴에 속한 상품의 수량은 0 이상이어야 한다. - 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - 메뉴는 특정 메뉴 그룹에 속해야 한다. @@ -18,9 +22,15 @@ - 메뉴의 목록을 조회할 수 있다. */ class MenuTest { - @DisplayName("메뉴를 생성할 수 있다.") + @DisplayName("메뉴의 가격을 변경할 수 있다.") @Test void construct() { - Menu menu = new Menu(); + final MenuPrice price = new MenuPrice(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final Menu menu = new Menu(price, name); + + menu.changePrice(new MenuPrice(BigDecimal.ONE)); + + assertThat(menu.getPrice()).isEqualTo(new MenuPrice(BigDecimal.ONE)); } } From 1c0a907fc9391ee529451e906953b5924803ec8a Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 17:25:45 +0900 Subject: [PATCH 08/50] =?UTF-8?q?refactor(DisplayedName):=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=EC=A0=9C=EC=96=B4=EC=9E=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java | 2 +- .../java/kitchenpos/products/tobe/domain/DisplayedName.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java index c9113f511..5a2d29290 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java @@ -4,7 +4,7 @@ import java.util.Objects; -public class DisplayedName { +class DisplayedName { private static final String EMPTY_NAME_MESSAGE = "메뉴 이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "메뉴 이름에 비속어가 포함될 수 없습니다."; diff --git a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java index 81e018396..efc777e94 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java @@ -2,7 +2,7 @@ import java.util.Objects; -public class DisplayedName { +class DisplayedName { private static final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; From fe09fae957f5113397398395b21cd1e022d167e6 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 17:28:28 +0900 Subject: [PATCH 09/50] =?UTF-8?q?refactor(Profanity):=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=EC=A0=9C=EC=96=B4=EC=9E=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kitchenpos/menus/tobe/domain/DisplayedName.java | 2 -- src/main/java/kitchenpos/menus/tobe/domain/Profanity.java | 5 +++++ src/main/java/kitchenpos/products/tobe/domain/Profanity.java | 2 +- .../java/kitchenpos/menus/tobe/domain/FakeProfanity.java | 2 -- 4 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/Profanity.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java index 5a2d29290..f6db240e2 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java @@ -1,7 +1,5 @@ package kitchenpos.menus.tobe.domain; -import kitchenpos.products.tobe.domain.Profanity; - import java.util.Objects; class DisplayedName { diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Profanity.java b/src/main/java/kitchenpos/menus/tobe/domain/Profanity.java new file mode 100644 index 000000000..b72c233f3 --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/Profanity.java @@ -0,0 +1,5 @@ +package kitchenpos.menus.tobe.domain; + +interface Profanity { + boolean isContains(String name); +} diff --git a/src/main/java/kitchenpos/products/tobe/domain/Profanity.java b/src/main/java/kitchenpos/products/tobe/domain/Profanity.java index 8cf48c31e..d8b93c8fd 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Profanity.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Profanity.java @@ -1,5 +1,5 @@ package kitchenpos.products.tobe.domain; -public interface Profanity { +interface Profanity { boolean isContains(String name); } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java b/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java index fdcd180bd..118416611 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java @@ -1,7 +1,5 @@ package kitchenpos.menus.tobe.domain; -import kitchenpos.products.tobe.domain.Profanity; - import java.util.List; class FakeProfanity implements Profanity { From cb82e2b5964d537b70a260252823a846227be49a Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 10 Oct 2022 17:38:23 +0900 Subject: [PATCH 10/50] =?UTF-8?q?feat(MenuProduct):=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=EC=97=90=20=EC=86=8D=ED=95=9C=20=EC=83=81=ED=92=88=EC=9D=98=20?= =?UTF-8?q?=EC=88=98=EB=9F=89=EC=9D=80=200=EB=B3=B4=EB=8B=A4=20=ED=81=AC?= =?UTF-8?q?=EA=B1=B0=EB=82=98=20=EA=B0=99=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/tobe/domain/MenuProduct.java | 14 +++++++++++++ .../menus/tobe/domain/MenuProductTest.java | 20 +++++++++++++++++++ .../menus/tobe/domain/MenuTest.java | 1 - 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java create mode 100644 src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java new file mode 100644 index 000000000..9b5e6d63c --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java @@ -0,0 +1,14 @@ +package kitchenpos.menus.tobe.domain; + +public class MenuProduct { + private static final String LESS_THAN_ZERO_MESSAGE = "수량은 0보다 작을 수 없습니다."; + + private long quantity; + + public MenuProduct(final long quantity) { + if (quantity < 0) { + new IllegalArgumentException(LESS_THAN_ZERO_MESSAGE); + } + this.quantity = quantity; + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java new file mode 100644 index 000000000..30052c666 --- /dev/null +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java @@ -0,0 +1,20 @@ +package kitchenpos.menus.tobe.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.assertj.core.api.Assertions.assertThatCode; + +/* +- [x] 메뉴에 속한 상품의 수량은 0보다 크거나 같아야한다. + */ +class MenuProductTest { + @DisplayName("메뉴에 속한 상품의 수량은 0보다 크거나 같다.") + @ParameterizedTest + @ValueSource(longs = {0L, 1L}) + void moreThanZeroAndEqualsQuantity(final long quantity) { + assertThatCode(() -> new MenuProduct(quantity)) + .doesNotThrowAnyException(); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index 62e7b4a48..ec7e796e8 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -10,7 +10,6 @@ /* - [x] 메뉴의 가격을 변경할 수 있다. - [x] 메뉴의 가격이 올바르지 않으면 변경할 수 없다. -- 메뉴에 속한 상품의 수량은 0 이상이어야 한다. - 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - 메뉴는 특정 메뉴 그룹에 속해야 한다. - 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. From e48c9773cf97f7e4e7251b120cec1c15fd995abf Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 19:01:05 +0900 Subject: [PATCH 11/50] =?UTF-8?q?refactor(DisplayedName):=20=EB=A9=94?= =?UTF-8?q?=EB=89=B4=EC=99=80=20=EC=83=81=ED=92=88=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kitchenpos/menus/tobe/domain/DisplayedName.java | 6 +++--- .../kitchenpos/menus/tobe/domain/DisplayedNameTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java index f6db240e2..3451a2a6c 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java @@ -3,12 +3,12 @@ import java.util.Objects; class DisplayedName { - private static final String EMPTY_NAME_MESSAGE = "메뉴 이름은 비어있을 수 없습니다."; - private static final String CONTAIN_PROFANITY_MESSAGE = "메뉴 이름에 비속어가 포함될 수 없습니다."; + private static final String EMPTY_NAME_MESSAGE = "이름은 비어있을 수 없습니다."; + private static final String CONTAIN_PROFANITY_MESSAGE = "이름에 비속어가 포함될 수 없습니다."; private final String name; - public DisplayedName(final String name, final Profanity profanity) { + DisplayedName(final String name, final Profanity profanity) { if (null == name || name.isBlank()) { throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java index 83431ae4f..843b008cf 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java @@ -16,7 +16,7 @@ class DisplayedNameTest { @NullAndEmptySource @ParameterizedTest void emptyName(final String name) { - final String EMPTY_NAME_MESSAGE = "메뉴 이름은 비어있을 수 없습니다."; + final String EMPTY_NAME_MESSAGE = "이름은 비어있을 수 없습니다."; assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) .isInstanceOf(IllegalArgumentException.class) @@ -26,7 +26,7 @@ void emptyName(final String name) { @DisplayName("메뉴 이름에 비속어가 포함될 수 없다.") @Test void registerWithProfanity() { - final String CONTAIN_PROFANITY_MESSAGE = "메뉴 이름에 비속어가 포함될 수 없습니다."; + final String CONTAIN_PROFANITY_MESSAGE = "이름에 비속어가 포함될 수 없습니다."; final String name = "damn"; assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) From d3142d2ca0e9eac6e8e2700c98c3318f5c1f15d7 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 19:01:47 +0900 Subject: [PATCH 12/50] =?UTF-8?q?refactor(Price):=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=EC=99=80=20=EC=83=81=ED=92=88=EC=97=90=EC=84=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/{MenuPrice.java => Price.java} | 19 ++++++++++++++----- .../{MenuPriceTest.java => PriceTest.java} | 10 +++++----- 2 files changed, 19 insertions(+), 10 deletions(-) rename src/main/java/kitchenpos/menus/tobe/domain/{MenuPrice.java => Price.java} (57%) rename src/test/java/kitchenpos/menus/tobe/domain/{MenuPriceTest.java => PriceTest.java} (76%) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java b/src/main/java/kitchenpos/menus/tobe/domain/Price.java similarity index 57% rename from src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java rename to src/main/java/kitchenpos/menus/tobe/domain/Price.java index 1a820bfab..d7c0a11bd 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuPrice.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Price.java @@ -3,13 +3,13 @@ import java.math.BigDecimal; import java.util.Objects; -public class MenuPrice { - private static final String EMPTY_NAME_MESSAGE = "메뉴 가격은 비어있을 수 없습니다."; - private static final String INVALID_PRICE_MESSAGE = "메뉴 가격은 0보다 크거다 같아야 합니다."; +class Price implements Comparable { + private static final String EMPTY_NAME_MESSAGE = "가격은 비어있을 수 없습니다."; + private static final String INVALID_PRICE_MESSAGE = "가격은 0보다 크거다 같아야 합니다."; private final BigDecimal price; - public MenuPrice(final BigDecimal price) { + Price(final BigDecimal price) { if (null == price) { throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); } @@ -19,11 +19,15 @@ public MenuPrice(final BigDecimal price) { this.price = price; } + public Price multiply(long quantity) { + return new Price(price.multiply(BigDecimal.valueOf(quantity))); + } + @Override public boolean equals(final Object o) { if (this == o) return true; if (null == o || getClass() != o.getClass()) return false; - final MenuPrice menuPrice = (MenuPrice) o; + final Price menuPrice = (Price) o; return price == null ? menuPrice.price == null : price.compareTo(menuPrice.price) == 0; } @@ -31,4 +35,9 @@ public boolean equals(final Object o) { public int hashCode() { return Objects.hash(price); } + + @Override + public int compareTo(final Price o) { + return price.subtract(o.price).intValue(); + } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java b/src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java similarity index 76% rename from src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java rename to src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java index 8ecd5915b..a781e524a 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuPriceTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java @@ -13,14 +13,14 @@ - [x] 메뉴의 가격은 0보다 크거나 같아야 한다. - [x] 메뉴의 가격이 올바르지 않으면 등록할 수 없다. (Null) */ -class MenuPriceTest { +class PriceTest { @DisplayName("메뉴의 가격은 0보다 크거나 같아야 한다.") @Test void registerWithLessThanZero() { - final String INVALID_PRICE_MESSAGE = "메뉴 가격은 0보다 크거다 같아야 합니다."; + final String INVALID_PRICE_MESSAGE = "가격은 0보다 크거다 같아야 합니다."; final BigDecimal price = BigDecimal.valueOf(-1L); - assertThatThrownBy(() -> new MenuPrice(price)) + assertThatThrownBy(() -> new Price(price)) .isInstanceOf(IllegalArgumentException.class) .hasMessage(INVALID_PRICE_MESSAGE); } @@ -29,9 +29,9 @@ void registerWithLessThanZero() { @NullSource @ParameterizedTest void registerWithEmptyName(final BigDecimal price) { - final String EMPTY_NAME_MESSAGE = "메뉴 가격은 비어있을 수 없습니다."; + final String EMPTY_NAME_MESSAGE = "가격은 비어있을 수 없습니다."; - assertThatThrownBy(() -> new MenuPrice(price)) + assertThatThrownBy(() -> new Price(price)) .isInstanceOf(IllegalArgumentException.class) .hasMessage(EMPTY_NAME_MESSAGE); } From 623c7ad50ba92d453c709b6a72c0cecf7c3b19dd Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 19:02:59 +0900 Subject: [PATCH 13/50] =?UTF-8?q?feat(Menu):=20=EB=A9=94=EB=89=B4=EC=97=90?= =?UTF-8?q?=20=EC=86=8D=ED=95=9C=20=EC=83=81=ED=92=88=20=EA=B8=88=EC=95=A1?= =?UTF-8?q?=EC=9D=98=20=ED=95=A9=EC=9D=80=20=EB=A9=94=EB=89=B4=EC=9D=98=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=EB=B3=B4=EB=8B=A4=20=ED=81=AC=EA=B1=B0?= =?UTF-8?q?=EB=82=98=20=EA=B0=99=EC=95=84=EC=95=BC=20=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/Menu.java | 15 ++++++++--- .../menus/tobe/domain/MenuProduct.java | 16 +++++++++++- .../menus/tobe/domain/MenuProductTest.java | 4 ++- .../menus/tobe/domain/MenuTest.java | 26 +++++++++++++++---- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 257f155fd..83d3d8e9f 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -1,19 +1,26 @@ package kitchenpos.menus.tobe.domain; public class Menu { - private MenuPrice price; + private static final String PRICE_INVALID_MESSAGE = "메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다."; + + private Price price; private DisplayedName name; + private MenuProduct menuProduct; - public Menu(final MenuPrice price, final DisplayedName name) { + public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct) { + if (menuProduct.getSumOfPrice().compareTo(price) < 0) { + throw new IllegalArgumentException(PRICE_INVALID_MESSAGE); + } this.price = price; this.name = name; + this.menuProduct = menuProduct; } - public MenuPrice getPrice() { + public Price getPrice() { return price; } - public void changePrice(final MenuPrice price) { + public void changePrice(final Price price) { this.price = price; } } diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java index 9b5e6d63c..69df143dd 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java @@ -1,14 +1,28 @@ package kitchenpos.menus.tobe.domain; +import java.math.BigDecimal; + public class MenuProduct { private static final String LESS_THAN_ZERO_MESSAGE = "수량은 0보다 작을 수 없습니다."; private long quantity; + private DisplayedName name; + private Price price; - public MenuProduct(final long quantity) { + public MenuProduct(final long quantity, final DisplayedName name, final Price price) { if (quantity < 0) { new IllegalArgumentException(LESS_THAN_ZERO_MESSAGE); } this.quantity = quantity; + this.name = name; + this.price = price; + } + + public MenuProduct(final long quantity, final DisplayedName name, final BigDecimal price) { + this(quantity, name, new Price(price)); + } + + public Price getSumOfPrice() { + return price.multiply(quantity); } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java index 30052c666..ad1d4af13 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java @@ -4,6 +4,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import java.math.BigDecimal; + import static org.assertj.core.api.Assertions.assertThatCode; /* @@ -14,7 +16,7 @@ class MenuProductTest { @ParameterizedTest @ValueSource(longs = {0L, 1L}) void moreThanZeroAndEqualsQuantity(final long quantity) { - assertThatCode(() -> new MenuProduct(quantity)) + assertThatCode(() -> new MenuProduct(quantity, new DisplayedName("양념치킨", new FakeProfanity()), BigDecimal.ZERO)) .doesNotThrowAnyException(); } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index ec7e796e8..cc33b3390 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -2,15 +2,18 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.math.BigDecimal; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; /* - [x] 메뉴의 가격을 변경할 수 있다. - [x] 메뉴의 가격이 올바르지 않으면 변경할 수 없다. -- 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. +- [x] 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - 메뉴는 특정 메뉴 그룹에 속해야 한다. - 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. - 상품이 없으면 등록할 수 없다. @@ -24,12 +27,25 @@ class MenuTest { @DisplayName("메뉴의 가격을 변경할 수 있다.") @Test void construct() { - final MenuPrice price = new MenuPrice(BigDecimal.TEN); + final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final Menu menu = new Menu(price, name); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(6L))); + final Menu menu = new Menu(price, name, menuProduct); + + menu.changePrice(new Price(BigDecimal.ONE)); - menu.changePrice(new MenuPrice(BigDecimal.ONE)); + assertThat(menu.getPrice()).isEqualTo(new Price(BigDecimal.ONE)); + } + + @DisplayName("메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다.") + @ParameterizedTest + @ValueSource(longs = {5L, 6L}) + void menuPriceIsGreaterThanAndEqualsMenuProductPriceSum(final long productPrice) { + final Price menuPrice = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(productPrice))); - assertThat(menu.getPrice()).isEqualTo(new MenuPrice(BigDecimal.ONE)); + assertThatCode(() -> new Menu(menuPrice, name, menuProduct)) + .doesNotThrowAnyException(); } } From f14b7f49b1af048722fa92fb2ac3226f82a53e13 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 19:19:01 +0900 Subject: [PATCH 14/50] =?UTF-8?q?feat(MenuGroup):=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=EB=8A=94=20=ED=8A=B9=EC=A0=95=20=EB=A9=94=EB=89=B4=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=EC=97=90=20=EC=86=8D=ED=95=B4=EC=95=BC=20=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/Menu.java | 4 +++- .../menus/tobe/domain/MenuGroup.java | 4 ++++ .../menus/tobe/domain/MenuTest.java | 20 +++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 83d3d8e9f..5b01eccff 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -6,14 +6,16 @@ public class Menu { private Price price; private DisplayedName name; private MenuProduct menuProduct; + private MenuGroup menuGroup; - public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct) { + public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct, final MenuGroup menuGroup) { if (menuProduct.getSumOfPrice().compareTo(price) < 0) { throw new IllegalArgumentException(PRICE_INVALID_MESSAGE); } this.price = price; this.name = name; this.menuProduct = menuProduct; + this.menuGroup = menuGroup; } public Price getPrice() { diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java new file mode 100644 index 000000000..862fb8862 --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java @@ -0,0 +1,4 @@ +package kitchenpos.menus.tobe.domain; + +class MenuGroup { +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index cc33b3390..e8409c104 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -14,7 +14,7 @@ - [x] 메뉴의 가격을 변경할 수 있다. - [x] 메뉴의 가격이 올바르지 않으면 변경할 수 없다. - [x] 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. -- 메뉴는 특정 메뉴 그룹에 속해야 한다. +- [x] 메뉴는 특정 메뉴 그룹에 속해야 한다. - 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. - 상품이 없으면 등록할 수 없다. - 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. @@ -30,7 +30,7 @@ void construct() { final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(6L))); - final Menu menu = new Menu(price, name, menuProduct); + final Menu menu = new Menu(price, name, menuProduct, new MenuGroup()); menu.changePrice(new Price(BigDecimal.ONE)); @@ -40,12 +40,24 @@ void construct() { @DisplayName("메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다.") @ParameterizedTest @ValueSource(longs = {5L, 6L}) - void menuPriceIsGreaterThanAndEqualsMenuProductPriceSum(final long productPrice) { + void greaterThanAndEqualsMenuProductPriceSum(final long productPrice) { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(productPrice))); - assertThatCode(() -> new Menu(menuPrice, name, menuProduct)) + assertThatCode(() -> new Menu(menuPrice, name, menuProduct, new MenuGroup())) + .doesNotThrowAnyException(); + } + + @DisplayName("메뉴는 특정 메뉴 그룹에 속해야 한다.") + @Test + void consistOfMenuGroup() { + final Price menuPrice = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(6L))); + final MenuGroup menuGroup = new MenuGroup(); + + assertThatCode(() -> new Menu(menuPrice, name, menuProduct, menuGroup)) .doesNotThrowAnyException(); } } From fcf969ce1f660e27c49a4dc677a26d9248e938b2 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 19:53:08 +0900 Subject: [PATCH 15/50] =?UTF-8?q?feat(Product):=20=EC=83=81=ED=92=88?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EC=9C=BC=EB=A9=B4=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=97=86=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/tobe/domain/MenuProduct.java | 14 ++++---------- .../kitchenpos/menus/tobe/domain/Product.java | 19 +++++++++++++++++++ .../menus/tobe/domain/MenuProductTest.java | 5 ++++- .../menus/tobe/domain/MenuTest.java | 9 +++------ 4 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 src/main/java/kitchenpos/menus/tobe/domain/Product.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java index 69df143dd..a6e965913 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java @@ -1,28 +1,22 @@ package kitchenpos.menus.tobe.domain; -import java.math.BigDecimal; - public class MenuProduct { private static final String LESS_THAN_ZERO_MESSAGE = "수량은 0보다 작을 수 없습니다."; private long quantity; private DisplayedName name; - private Price price; + private Product product; - public MenuProduct(final long quantity, final DisplayedName name, final Price price) { + public MenuProduct(final long quantity, final DisplayedName name, final Product product) { if (quantity < 0) { new IllegalArgumentException(LESS_THAN_ZERO_MESSAGE); } this.quantity = quantity; this.name = name; - this.price = price; - } - - public MenuProduct(final long quantity, final DisplayedName name, final BigDecimal price) { - this(quantity, name, new Price(price)); + this.product = product; } public Price getSumOfPrice() { - return price.multiply(quantity); + return product.getPrice().multiply(quantity); } } diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Product.java b/src/main/java/kitchenpos/menus/tobe/domain/Product.java new file mode 100644 index 000000000..88d39fcd6 --- /dev/null +++ b/src/main/java/kitchenpos/menus/tobe/domain/Product.java @@ -0,0 +1,19 @@ +package kitchenpos.menus.tobe.domain; + +import java.math.BigDecimal; + +class Product { + private Price price; + + public Product(final Price price) { + this.price = price; + } + + public Product(final BigDecimal price) { + this(new Price(price)); + } + + public Price getPrice() { + return price; + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java index ad1d4af13..c0dcc5738 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java @@ -10,13 +10,16 @@ /* - [x] 메뉴에 속한 상품의 수량은 0보다 크거나 같아야한다. +- [x] 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. +- [x] 상품이 없으면 등록할 수 없다. */ class MenuProductTest { @DisplayName("메뉴에 속한 상품의 수량은 0보다 크거나 같다.") @ParameterizedTest @ValueSource(longs = {0L, 1L}) void moreThanZeroAndEqualsQuantity(final long quantity) { - assertThatCode(() -> new MenuProduct(quantity, new DisplayedName("양념치킨", new FakeProfanity()), BigDecimal.ZERO)) + final Product product = new Product(BigDecimal.ONE); + assertThatCode(() -> new MenuProduct(quantity, new DisplayedName("양념치킨", new FakeProfanity()), product)) .doesNotThrowAnyException(); } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index e8409c104..3a88688de 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -15,9 +15,6 @@ - [x] 메뉴의 가격이 올바르지 않으면 변경할 수 없다. - [x] 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - [x] 메뉴는 특정 메뉴 그룹에 속해야 한다. -- 1 개 이상의 등록된 상품으로 메뉴를 등록할 수 있다. -- 상품이 없으면 등록할 수 없다. -- 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - 메뉴를 노출할 수 있다. - 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다. - 메뉴를 숨길 수 있다. @@ -29,7 +26,7 @@ class MenuTest { void construct() { final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(6L))); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(6L))); final Menu menu = new Menu(price, name, menuProduct, new MenuGroup()); menu.changePrice(new Price(BigDecimal.ONE)); @@ -43,7 +40,7 @@ void construct() { void greaterThanAndEqualsMenuProductPriceSum(final long productPrice) { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(productPrice))); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(productPrice))); assertThatCode(() -> new Menu(menuPrice, name, menuProduct, new MenuGroup())) .doesNotThrowAnyException(); @@ -54,7 +51,7 @@ void greaterThanAndEqualsMenuProductPriceSum(final long productPrice) { void consistOfMenuGroup() { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Price(BigDecimal.valueOf(6L))); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(6L))); final MenuGroup menuGroup = new MenuGroup(); assertThatCode(() -> new Menu(menuPrice, name, menuProduct, menuGroup)) From eac46ca734a76858ee6d65e8322787d3bab297ed Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 20:09:38 +0900 Subject: [PATCH 16/50] =?UTF-8?q?feat(Menu):=20=EB=A9=94=EB=89=B4=EC=9D=98?= =?UTF-8?q?=20=EC=A0=84=EC=8B=9C=EC=83=81=ED=83=9C=EB=A5=BC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +-- .../kitchenpos/menus/tobe/domain/Menu.java | 13 +++++++++++++ .../menus/tobe/domain/MenuTest.java | 19 +++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4a91e3f71..15c26becc 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,8 @@ docker compose -p kitchenpos up -d - 메뉴의 가격이 올바르지 않으면 변경할 수 없다. - 메뉴의 가격은 0원 이상이어야 한다. - 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. -- 메뉴를 노출할 수 있다. +- 메뉴의 전시상태를 변경할 수 있다. (노출, 숨김) - 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다. -- 메뉴를 숨길 수 있다. - 메뉴의 목록을 조회할 수 있다. ### 주문 테이블 diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 5b01eccff..9ccef8e6f 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -7,6 +7,7 @@ public class Menu { private DisplayedName name; private MenuProduct menuProduct; private MenuGroup menuGroup; + private boolean displayed; public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct, final MenuGroup menuGroup) { if (menuProduct.getSumOfPrice().compareTo(price) < 0) { @@ -16,6 +17,7 @@ public Menu(final Price price, final DisplayedName name, final MenuProduct menuP this.name = name; this.menuProduct = menuProduct; this.menuGroup = menuGroup; + this.displayed = true; } public Price getPrice() { @@ -25,4 +27,15 @@ public Price getPrice() { public void changePrice(final Price price) { this.price = price; } + + public boolean isDisplayed() { + return this.displayed; + } + public void displayOff() { + this.displayed = false; + } + + public void displayOn() { + this.displayed = true; + } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index 3a88688de..58218e215 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -15,9 +15,8 @@ - [x] 메뉴의 가격이 올바르지 않으면 변경할 수 없다. - [x] 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - [x] 메뉴는 특정 메뉴 그룹에 속해야 한다. -- 메뉴를 노출할 수 있다. +- [x] 메뉴의 전시상태를 변경할 수 있다. (노출, 숨김) - 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다. -- 메뉴를 숨길 수 있다. - 메뉴의 목록을 조회할 수 있다. */ class MenuTest { @@ -57,4 +56,20 @@ void consistOfMenuGroup() { assertThatCode(() -> new Menu(menuPrice, name, menuProduct, menuGroup)) .doesNotThrowAnyException(); } + + @DisplayName("메뉴의 전시상태를 변경할 수 있다.") + @Test + void displayed() { + final Price menuPrice = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(6L))); + final MenuGroup menuGroup = new MenuGroup(); + + final Menu menu = new Menu(menuPrice, name, menuProduct, menuGroup); + menu.displayOff(); + assertThat(menu.isDisplayed()).isFalse(); + + menu.displayOn(); + assertThat(menu.isDisplayed()).isTrue(); + } } From d55cda4c95798d092d3e44964e53c08749b002fd Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 13 Oct 2022 20:48:18 +0900 Subject: [PATCH 17/50] =?UTF-8?q?feat(Menu):=20=EB=A9=94=EB=89=B4=EC=9D=98?= =?UTF-8?q?=20=EA=B0=80=EA=B2=A9=EC=9D=B4=20=EB=A9=94=EB=89=B4=EC=97=90=20?= =?UTF-8?q?=EC=86=8D=ED=95=9C=20=EC=83=81=ED=92=88=20=EA=B8=88=EC=95=A1?= =?UTF-8?q?=EC=9D=98=20=ED=95=A9=EB=B3=B4=EB=8B=A4=20=EB=86=92=EC=9D=84=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EB=A9=94=EB=89=B4=EB=A5=BC=20=EB=85=B8?= =?UTF-8?q?=EC=B6=9C=ED=95=A0=20=EC=88=98=20=EC=97=86=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/Menu.java | 25 ++++++++++++---- .../menus/tobe/domain/MenuTest.java | 29 +++++++++++++++++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 9ccef8e6f..db9dacc48 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -1,8 +1,7 @@ package kitchenpos.menus.tobe.domain; public class Menu { - private static final String PRICE_INVALID_MESSAGE = "메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다."; - + private static final String CAN_NOT_DISPLAY_MESSAGE = "메뉴의 가격은 상품 가격의 합보다 작다면 전시할 수 없습니다."; private Price price; private DisplayedName name; private MenuProduct menuProduct; @@ -10,14 +9,11 @@ public class Menu { private boolean displayed; public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct, final MenuGroup menuGroup) { - if (menuProduct.getSumOfPrice().compareTo(price) < 0) { - throw new IllegalArgumentException(PRICE_INVALID_MESSAGE); - } + decideDisplay(menuProduct, price); this.price = price; this.name = name; this.menuProduct = menuProduct; this.menuGroup = menuGroup; - this.displayed = true; } public Price getPrice() { @@ -25,17 +21,34 @@ public Price getPrice() { } public void changePrice(final Price price) { + decideDisplay(this.menuProduct, price); this.price = price; } public boolean isDisplayed() { return this.displayed; } + public void displayOff() { this.displayed = false; } public void displayOn() { + validateDisplay(); + this.displayed = true; + } + + private void decideDisplay(final MenuProduct menuProduct, final Price price) { + if (menuProduct.getSumOfPrice().compareTo(price) < 0) { + this.displayed = false; + return; + } this.displayed = true; } + + private void validateDisplay() { + if (menuProduct.getSumOfPrice().compareTo(price) < 0) { + throw new IllegalArgumentException(CAN_NOT_DISPLAY_MESSAGE); + } + } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index 58218e215..163c7b1fd 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -9,6 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /* - [x] 메뉴의 가격을 변경할 수 있다. @@ -16,8 +17,7 @@ - [x] 메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다. - [x] 메뉴는 특정 메뉴 그룹에 속해야 한다. - [x] 메뉴의 전시상태를 변경할 수 있다. (노출, 숨김) -- 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다. -- 메뉴의 목록을 조회할 수 있다. +- [x] 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다. */ class MenuTest { @DisplayName("메뉴의 가격을 변경할 수 있다.") @@ -72,4 +72,29 @@ void displayed() { menu.displayOn(); assertThat(menu.isDisplayed()).isTrue(); } + + @DisplayName("메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 높을 경우 메뉴를 노출할 수 없다.") + @Test + void displayOffWithInvalidPrice() { + String message = "메뉴의 가격은 상품 가격의 합보다 작다면 전시할 수 없습니다."; + + final Price menuPrice = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(4L))); + final MenuGroup menuGroup = new MenuGroup(); + + final Menu menu = new Menu(menuPrice, name, menuProduct, menuGroup); + assertThat(menu.isDisplayed()).isFalse(); + + assertThatThrownBy(() -> menu.displayOn()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(message); + + menu.changePrice(new Price(BigDecimal.valueOf(8L))); + menu.displayOn(); + assertThat(menu.isDisplayed()).isTrue(); + + menu.changePrice(new Price(BigDecimal.TEN)); + assertThat(menu.isDisplayed()).isFalse(); + } } From 40d49e0247283307f08a7fd08f2b5e65414bf6c9 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 19:02:31 +0900 Subject: [PATCH 18/50] =?UTF-8?q?feat(ProductRestController):=20create=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tobe/infra/ProductRestController.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java diff --git a/src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java b/src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java new file mode 100644 index 000000000..e70a1742b --- /dev/null +++ b/src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java @@ -0,0 +1,28 @@ +package kitchenpos.products.tobe.infra; + +import kitchenpos.products.domain.Product; +import kitchenpos.products.tobe.application.ProductService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.net.URI; + +@RequestMapping("/api/products") +@RestController +public class ProductRestController { + private final ProductService productService; + + public ProductRestController(final ProductService productService) { + this.productService = productService; + } + + @PostMapping + public ResponseEntity create(@RequestBody final Product request) { + final Product response = productService.create(request); + return ResponseEntity.created(URI.create("/api/products/" + response.getId())) + .body(response); + } +} From 728ef0744af9ccd77db38ac5470d0a679ac826a5 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 20:30:20 +0900 Subject: [PATCH 19/50] =?UTF-8?q?refactor(MenuProduct):=20menuProduct?= =?UTF-8?q?=EC=9D=98=20=EA=B0=80=EA=B2=A9=EB=B9=84=EA=B5=90=EB=8A=94=20Men?= =?UTF-8?q?uProduct=EC=97=90=EC=84=9C=20=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/tobe/domain/Menu.java | 4 +-- .../menus/tobe/domain/MenuProduct.java | 7 +++++ .../tobe/infra/ProductRestController.java | 28 ------------------- 3 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index db9dacc48..4ab69dfbb 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -39,7 +39,7 @@ public void displayOn() { } private void decideDisplay(final MenuProduct menuProduct, final Price price) { - if (menuProduct.getSumOfPrice().compareTo(price) < 0) { + if (menuProduct.lessThan(price)) { this.displayed = false; return; } @@ -47,7 +47,7 @@ private void decideDisplay(final MenuProduct menuProduct, final Price price) { } private void validateDisplay() { - if (menuProduct.getSumOfPrice().compareTo(price) < 0) { + if (menuProduct.lessThan(price)) { throw new IllegalArgumentException(CAN_NOT_DISPLAY_MESSAGE); } } diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java index a6e965913..ed32613d5 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java @@ -19,4 +19,11 @@ public MenuProduct(final long quantity, final DisplayedName name, final Product public Price getSumOfPrice() { return product.getPrice().multiply(quantity); } + + public boolean lessThan(final Price price) { + if (this.getSumOfPrice().compareTo(price) < 0) { + return true; + } + return false; + } } diff --git a/src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java b/src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java deleted file mode 100644 index e70a1742b..000000000 --- a/src/main/java/kitchenpos/products/tobe/infra/ProductRestController.java +++ /dev/null @@ -1,28 +0,0 @@ -package kitchenpos.products.tobe.infra; - -import kitchenpos.products.domain.Product; -import kitchenpos.products.tobe.application.ProductService; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.net.URI; - -@RequestMapping("/api/products") -@RestController -public class ProductRestController { - private final ProductService productService; - - public ProductRestController(final ProductService productService) { - this.productService = productService; - } - - @PostMapping - public ResponseEntity create(@RequestBody final Product request) { - final Product response = productService.create(request); - return ResponseEntity.created(URI.create("/api/products/" + response.getId())) - .body(response); - } -} From 15219120607195ff9d3d2b769b3d1e972177e34c Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 20:46:47 +0900 Subject: [PATCH 20/50] =?UTF-8?q?refactor(Product):=20JPA=20Entity?= =?UTF-8?q?=EC=97=90=20=EA=B0=92=EA=B0=9D=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../products/tobe/domain/DisplayedName.java | 8 +++++++ .../products/tobe/domain/Product.java | 23 +++++++++++++++++++ .../products/tobe/domain/ProductPrice.java | 8 +++++++ 3 files changed, 39 insertions(+) diff --git a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java index efc777e94..824b3c1c5 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java @@ -1,11 +1,15 @@ package kitchenpos.products.tobe.domain; +import javax.persistence.Column; +import javax.persistence.Embeddable; import java.util.Objects; +@Embeddable class DisplayedName { private static final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; + @Column(name = "name", nullable = false) private final String name; public DisplayedName(final String name, final Profanity profanity) { @@ -18,6 +22,10 @@ public DisplayedName(final String name, final Profanity profanity) { this.name = name; } + protected DisplayedName() { + this.name = null; + } + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/main/java/kitchenpos/products/tobe/domain/Product.java b/src/main/java/kitchenpos/products/tobe/domain/Product.java index 5ed07836b..98564b1eb 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Product.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Product.java @@ -1,7 +1,23 @@ package kitchenpos.products.tobe.domain; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.UUID; + +@Table(name = "product") +@Entity public class Product { + @Column(name = "id", columnDefinition = "binary(16)") + @Id + private UUID id; + + @Embedded private ProductPrice price; + + @Embedded private DisplayedName name; public Product(final ProductPrice price, final DisplayedName name) { @@ -9,6 +25,13 @@ public Product(final ProductPrice price, final DisplayedName name) { this.name = name; } + protected Product() { + } + + public UUID getId() { + return id; + } + public void changePrice(final ProductPrice price) { this.price = price; } diff --git a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java index 6ae291544..f91745942 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java +++ b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java @@ -1,11 +1,15 @@ package kitchenpos.products.tobe.domain; +import javax.persistence.Column; +import javax.persistence.Embeddable; import java.math.BigDecimal; import java.util.Objects; +@Embeddable public class ProductPrice { private static final String INVALID_PRICE_MESSAGE = "상품 가격은 0보다 크거다 같아야 합니다."; + @Column(name = "price", nullable = false) private final BigDecimal price; public ProductPrice(final BigDecimal price) { @@ -15,6 +19,10 @@ public ProductPrice(final BigDecimal price) { this.price = price; } + public ProductPrice() { + this.price = null; + } + @Override public boolean equals(final Object o) { if (this == o) return true; From 65c7a616db3dea4cae96977a0d90a4b4a0524b02 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 20:55:26 +0900 Subject: [PATCH 21/50] =?UTF-8?q?refactor(Profanity):=20PurgomalumClient?= =?UTF-8?q?=EB=A5=BC=20Profanities=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/application/MenuService.java | 7 +- .../kitchenpos/products/domain/Product.java | 98 +++++++++---------- .../infra/DefaultPurgomalumClient.java | 2 +- ...PurgomalumClient.java => Profanities.java} | 2 +- .../products/tobe/domain/DisplayedName.java | 8 +- .../products/tobe/domain/Profanity.java | 5 - .../menus/application/MenuServiceTest.java | 5 +- .../application/FakePurgomalumClient.java | 4 +- .../application/ProductServiceTest.java | 5 +- .../tobe/domain/DisplayedNameTest.java | 4 +- .../products/tobe/domain/FakeProfanities.java | 14 +++ .../products/tobe/domain/FakeProfanity.java | 12 --- .../products/tobe/domain/ProductTest.java | 4 +- 13 files changed, 83 insertions(+), 87 deletions(-) rename src/main/java/kitchenpos/products/infra/{PurgomalumClient.java => Profanities.java} (69%) delete mode 100644 src/main/java/kitchenpos/products/tobe/domain/Profanity.java create mode 100644 src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java delete mode 100644 src/test/java/kitchenpos/products/tobe/domain/FakeProfanity.java diff --git a/src/main/java/kitchenpos/menus/application/MenuService.java b/src/main/java/kitchenpos/menus/application/MenuService.java index abf913c11..f6dea396f 100644 --- a/src/main/java/kitchenpos/menus/application/MenuService.java +++ b/src/main/java/kitchenpos/menus/application/MenuService.java @@ -1,9 +1,8 @@ package kitchenpos.menus.application; import kitchenpos.menus.domain.*; -import kitchenpos.products.domain.Product; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.PurgomalumClient; +import kitchenpos.products.infra.Profanities; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,13 +15,13 @@ public class MenuService { private final MenuRepository menuRepository; private final MenuGroupRepository menuGroupRepository; private final ProductRepository productRepository; - private final PurgomalumClient purgomalumClient; + private final Profanities purgomalumClient; public MenuService( final MenuRepository menuRepository, final MenuGroupRepository menuGroupRepository, final ProductRepository productRepository, - final PurgomalumClient purgomalumClient + final Profanities purgomalumClient ) { this.menuRepository = menuRepository; this.menuGroupRepository = menuGroupRepository; diff --git a/src/main/java/kitchenpos/products/domain/Product.java b/src/main/java/kitchenpos/products/domain/Product.java index 456864e20..0fb09d861 100644 --- a/src/main/java/kitchenpos/products/domain/Product.java +++ b/src/main/java/kitchenpos/products/domain/Product.java @@ -1,49 +1,49 @@ -package kitchenpos.products.domain; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.math.BigDecimal; -import java.util.UUID; - -@Table(name = "product") -@Entity -public class Product { - @Column(name = "id", columnDefinition = "binary(16)") - @Id - private UUID id; - - @Column(name = "name", nullable = false) - private String name; - - @Column(name = "price", nullable = false) - private BigDecimal price; - - public Product() { - } - - public UUID getId() { - return id; - } - - public void setId(final UUID id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(final BigDecimal price) { - this.price = price; - } -} +//package kitchenpos.products.domain; +// +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.Id; +//import javax.persistence.Table; +//import java.math.BigDecimal; +//import java.util.UUID; +// +//@Table(name = "product") +//@Entity +//public class Product { +// @Column(name = "id", columnDefinition = "binary(16)") +// @Id +// private UUID id; +// +// @Column(name = "name", nullable = false) +// private String name; +// +// @Column(name = "price", nullable = false) +// private BigDecimal price; +// +// public Product() { +// } +// +// public UUID getId() { +// return id; +// } +// +// public void setId(final UUID id) { +// this.id = id; +// } +// +// public String getName() { +// return name; +// } +// +// public void setName(final String name) { +// this.name = name; +// } +// +// public BigDecimal getPrice() { +// return price; +// } +// +// public void setPrice(final BigDecimal price) { +// this.price = price; +// } +//} diff --git a/src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java b/src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java index 87dba885c..945177a79 100644 --- a/src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java +++ b/src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java @@ -8,7 +8,7 @@ import java.net.URI; @Component -public class DefaultPurgomalumClient implements PurgomalumClient { +public class DefaultPurgomalumClient implements Profanities { private final RestTemplate restTemplate; public DefaultPurgomalumClient(final RestTemplateBuilder restTemplateBuilder) { diff --git a/src/main/java/kitchenpos/products/infra/PurgomalumClient.java b/src/main/java/kitchenpos/products/infra/Profanities.java similarity index 69% rename from src/main/java/kitchenpos/products/infra/PurgomalumClient.java rename to src/main/java/kitchenpos/products/infra/Profanities.java index 4002a2bb8..93739ef5b 100644 --- a/src/main/java/kitchenpos/products/infra/PurgomalumClient.java +++ b/src/main/java/kitchenpos/products/infra/Profanities.java @@ -1,5 +1,5 @@ package kitchenpos.products.infra; -public interface PurgomalumClient { +public interface Profanities { boolean containsProfanity(String text); } diff --git a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java index 824b3c1c5..da49a4eee 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java @@ -1,22 +1,24 @@ package kitchenpos.products.tobe.domain; +import kitchenpos.products.infra.Profanities; + import javax.persistence.Column; import javax.persistence.Embeddable; import java.util.Objects; @Embeddable -class DisplayedName { +public class DisplayedName { private static final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; @Column(name = "name", nullable = false) private final String name; - public DisplayedName(final String name, final Profanity profanity) { + public DisplayedName(final String name, final Profanities profanities) { if (null == name || name.isBlank()) { throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); } - if (profanity.isContains(name)) { + if (profanities.containsProfanity(name)) { throw new IllegalArgumentException(CONTAIN_PROFANITY_MESSAGE); } this.name = name; diff --git a/src/main/java/kitchenpos/products/tobe/domain/Profanity.java b/src/main/java/kitchenpos/products/tobe/domain/Profanity.java deleted file mode 100644 index d8b93c8fd..000000000 --- a/src/main/java/kitchenpos/products/tobe/domain/Profanity.java +++ /dev/null @@ -1,5 +0,0 @@ -package kitchenpos.products.tobe.domain; - -interface Profanity { - boolean isContains(String name); -} diff --git a/src/test/java/kitchenpos/menus/application/MenuServiceTest.java b/src/test/java/kitchenpos/menus/application/MenuServiceTest.java index 23f260848..ce9475eaf 100644 --- a/src/test/java/kitchenpos/menus/application/MenuServiceTest.java +++ b/src/test/java/kitchenpos/menus/application/MenuServiceTest.java @@ -6,9 +6,8 @@ import kitchenpos.menus.domain.MenuRepository; import kitchenpos.products.application.FakePurgomalumClient; import kitchenpos.products.application.InMemoryProductRepository; -import kitchenpos.products.domain.Product; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.PurgomalumClient; +import kitchenpos.products.infra.Profanities; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -30,7 +29,7 @@ class MenuServiceTest { private MenuRepository menuRepository; private MenuGroupRepository menuGroupRepository; private ProductRepository productRepository; - private PurgomalumClient purgomalumClient; + private Profanities purgomalumClient; private MenuService menuService; private UUID menuGroupId; private Product product; diff --git a/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java b/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java index 3c4114798..f10e034d8 100644 --- a/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java +++ b/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java @@ -1,11 +1,11 @@ package kitchenpos.products.application; -import kitchenpos.products.infra.PurgomalumClient; +import kitchenpos.products.infra.Profanities; import java.util.Arrays; import java.util.List; -public class FakePurgomalumClient implements PurgomalumClient { +public class FakePurgomalumClient implements Profanities { private static final List profanities; static { diff --git a/src/test/java/kitchenpos/products/application/ProductServiceTest.java b/src/test/java/kitchenpos/products/application/ProductServiceTest.java index 30cc6fb7a..a4c448cb2 100644 --- a/src/test/java/kitchenpos/products/application/ProductServiceTest.java +++ b/src/test/java/kitchenpos/products/application/ProductServiceTest.java @@ -3,9 +3,8 @@ import kitchenpos.menus.application.InMemoryMenuRepository; import kitchenpos.menus.domain.Menu; import kitchenpos.menus.domain.MenuRepository; -import kitchenpos.products.domain.Product; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.PurgomalumClient; +import kitchenpos.products.infra.Profanities; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -25,7 +24,7 @@ class ProductServiceTest { private ProductRepository productRepository; private MenuRepository menuRepository; - private PurgomalumClient purgomalumClient; + private Profanities purgomalumClient; private ProductService productService; @BeforeEach diff --git a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java index 88cc13d53..e100542e4 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java @@ -14,7 +14,7 @@ class DisplayedNameTest { void emptyName(final String name) { final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; - assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanities())) .isInstanceOf(IllegalArgumentException.class) .hasMessage(EMPTY_NAME_MESSAGE); } @@ -25,7 +25,7 @@ void registerWithProfanity() { final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; final String name = "damn"; - assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanities())) .isInstanceOf(IllegalArgumentException.class) .hasMessage(CONTAIN_PROFANITY_MESSAGE); } diff --git a/src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java b/src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java new file mode 100644 index 000000000..e23d87b2a --- /dev/null +++ b/src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java @@ -0,0 +1,14 @@ +package kitchenpos.products.tobe.domain; + +import kitchenpos.products.infra.Profanities; + +import java.util.List; + +class FakeProfanities implements Profanities { + private final List values = List.of("damn"); + + @Override + public boolean containsProfanity(final String text) { + return values.contains(text); + } +} diff --git a/src/test/java/kitchenpos/products/tobe/domain/FakeProfanity.java b/src/test/java/kitchenpos/products/tobe/domain/FakeProfanity.java deleted file mode 100644 index 3faf35f45..000000000 --- a/src/test/java/kitchenpos/products/tobe/domain/FakeProfanity.java +++ /dev/null @@ -1,12 +0,0 @@ -package kitchenpos.products.tobe.domain; - -import java.util.List; - -class FakeProfanity implements Profanity { - private final List values = List.of("damn"); - - @Override - public boolean isContains(final String name) { - return values.contains(name); - } -} diff --git a/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java b/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java index d0bc8a319..cfc2da10d 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java @@ -12,7 +12,7 @@ class ProductTest { @Test void register() { final ProductPrice price = new ProductPrice(BigDecimal.TEN); - final DisplayedName name = new DisplayedName("chicken", new FakeProfanity()); + final DisplayedName name = new DisplayedName("chicken", new FakeProfanities()); assertThatCode(() -> new Product(price, name)) .doesNotThrowAnyException(); @@ -22,7 +22,7 @@ void register() { @Test void changePrice() { final ProductPrice price = new ProductPrice(BigDecimal.TEN); - final DisplayedName name = new DisplayedName("chicken", new FakeProfanity()); + final DisplayedName name = new DisplayedName("chicken", new FakeProfanities()); Product product = new Product(price, name); product.changePrice(new ProductPrice(BigDecimal.ONE)); From 36aa0b10888badb0a94836ab1a5dabf969ede76e Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 20:59:51 +0900 Subject: [PATCH 22/50] =?UTF-8?q?feat(ProductRequest):=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../products/application/dto/ProductRequest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/kitchenpos/products/application/dto/ProductRequest.java diff --git a/src/main/java/kitchenpos/products/application/dto/ProductRequest.java b/src/main/java/kitchenpos/products/application/dto/ProductRequest.java new file mode 100644 index 000000000..5d1a327c8 --- /dev/null +++ b/src/main/java/kitchenpos/products/application/dto/ProductRequest.java @@ -0,0 +1,16 @@ +package kitchenpos.products.application.dto; + +import java.math.BigDecimal; + +public class ProductRequest { + private BigDecimal price; + private String name; + + public BigDecimal getPrice() { + return price; + } + + public String getName() { + return name; + } +} From 983e8d4d93893abeed7f5e6a7142c67508afba59 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:00:35 +0900 Subject: [PATCH 23/50] =?UTF-8?q?feat(Product):=20tobe=EC=9D=98=20Product?= =?UTF-8?q?=EB=A1=9C=20=EB=8C=80=EC=B2=B4=ED=95=98=EA=B3=A0=20create=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../products/application/ProductService.java | 39 ++++++--------- .../products/domain/JpaProductRepository.java | 1 + .../kitchenpos/products/domain/Product.java | 49 ------------------- .../products/domain/ProductRepository.java | 2 + .../products/tobe/domain/Product.java | 8 +++ .../products/ui/ProductRestController.java | 15 ++++-- 6 files changed, 38 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/kitchenpos/products/domain/Product.java diff --git a/src/main/java/kitchenpos/products/application/ProductService.java b/src/main/java/kitchenpos/products/application/ProductService.java index 20cf63996..8cfc99dc8 100644 --- a/src/main/java/kitchenpos/products/application/ProductService.java +++ b/src/main/java/kitchenpos/products/application/ProductService.java @@ -3,9 +3,12 @@ import kitchenpos.menus.domain.Menu; import kitchenpos.menus.domain.MenuProduct; import kitchenpos.menus.domain.MenuRepository; -import kitchenpos.products.domain.Product; +import kitchenpos.products.application.dto.ProductRequest; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.PurgomalumClient; +import kitchenpos.products.infra.Profanities; +import kitchenpos.products.tobe.domain.DisplayedName; +import kitchenpos.products.tobe.domain.Product; +import kitchenpos.products.tobe.domain.ProductPrice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,12 +22,12 @@ public class ProductService { private final ProductRepository productRepository; private final MenuRepository menuRepository; - private final PurgomalumClient purgomalumClient; + private final Profanities purgomalumClient; public ProductService( - final ProductRepository productRepository, - final MenuRepository menuRepository, - final PurgomalumClient purgomalumClient + final ProductRepository productRepository, + final MenuRepository menuRepository, + final Profanities purgomalumClient ) { this.productRepository = productRepository; this.menuRepository = menuRepository; @@ -32,19 +35,9 @@ public ProductService( } @Transactional - public Product create(final Product request) { - final BigDecimal price = request.getPrice(); - if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) { - throw new IllegalArgumentException(); - } - final String name = request.getName(); - if (Objects.isNull(name) || purgomalumClient.containsProfanity(name)) { - throw new IllegalArgumentException(); - } - final Product product = new Product(); - product.setId(UUID.randomUUID()); - product.setName(name); - product.setPrice(price); + public Product create(final ProductRequest request) { + final Product product = new Product( + new ProductPrice(request.getPrice()), new DisplayedName(request.getName(), purgomalumClient)); return productRepository.save(product); } @@ -55,16 +48,16 @@ public Product changePrice(final UUID productId, final Product request) { throw new IllegalArgumentException(); } final Product product = productRepository.findById(productId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); product.setPrice(price); final List menus = menuRepository.findAllByProductId(productId); for (final Menu menu : menus) { BigDecimal sum = BigDecimal.ZERO; for (final MenuProduct menuProduct : menu.getMenuProducts()) { sum = sum.add( - menuProduct.getProduct() - .getPrice() - .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) + menuProduct.getProduct() + .getPrice() + .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) ); } if (menu.getPrice().compareTo(sum) > 0) { diff --git a/src/main/java/kitchenpos/products/domain/JpaProductRepository.java b/src/main/java/kitchenpos/products/domain/JpaProductRepository.java index 90b069779..e78c2112d 100644 --- a/src/main/java/kitchenpos/products/domain/JpaProductRepository.java +++ b/src/main/java/kitchenpos/products/domain/JpaProductRepository.java @@ -1,5 +1,6 @@ package kitchenpos.products.domain; +import kitchenpos.products.tobe.domain.Product; import org.springframework.data.jpa.repository.JpaRepository; import java.util.UUID; diff --git a/src/main/java/kitchenpos/products/domain/Product.java b/src/main/java/kitchenpos/products/domain/Product.java deleted file mode 100644 index 0fb09d861..000000000 --- a/src/main/java/kitchenpos/products/domain/Product.java +++ /dev/null @@ -1,49 +0,0 @@ -//package kitchenpos.products.domain; -// -//import javax.persistence.Column; -//import javax.persistence.Entity; -//import javax.persistence.Id; -//import javax.persistence.Table; -//import java.math.BigDecimal; -//import java.util.UUID; -// -//@Table(name = "product") -//@Entity -//public class Product { -// @Column(name = "id", columnDefinition = "binary(16)") -// @Id -// private UUID id; -// -// @Column(name = "name", nullable = false) -// private String name; -// -// @Column(name = "price", nullable = false) -// private BigDecimal price; -// -// public Product() { -// } -// -// public UUID getId() { -// return id; -// } -// -// public void setId(final UUID id) { -// this.id = id; -// } -// -// public String getName() { -// return name; -// } -// -// public void setName(final String name) { -// this.name = name; -// } -// -// public BigDecimal getPrice() { -// return price; -// } -// -// public void setPrice(final BigDecimal price) { -// this.price = price; -// } -//} diff --git a/src/main/java/kitchenpos/products/domain/ProductRepository.java b/src/main/java/kitchenpos/products/domain/ProductRepository.java index 3637e4232..31a3ad0d8 100644 --- a/src/main/java/kitchenpos/products/domain/ProductRepository.java +++ b/src/main/java/kitchenpos/products/domain/ProductRepository.java @@ -1,5 +1,7 @@ package kitchenpos.products.domain; +import kitchenpos.products.tobe.domain.Product; + import java.util.List; import java.util.Optional; import java.util.UUID; diff --git a/src/main/java/kitchenpos/products/tobe/domain/Product.java b/src/main/java/kitchenpos/products/tobe/domain/Product.java index 98564b1eb..060fb3681 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Product.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Product.java @@ -32,6 +32,14 @@ public UUID getId() { return id; } + public ProductPrice getPrice() { + return price; + } + + public DisplayedName getName() { + return name; + } + public void changePrice(final ProductPrice price) { this.price = price; } diff --git a/src/main/java/kitchenpos/products/ui/ProductRestController.java b/src/main/java/kitchenpos/products/ui/ProductRestController.java index 7dc532ec2..312da8cb9 100644 --- a/src/main/java/kitchenpos/products/ui/ProductRestController.java +++ b/src/main/java/kitchenpos/products/ui/ProductRestController.java @@ -1,9 +1,16 @@ package kitchenpos.products.ui; import kitchenpos.products.application.ProductService; -import kitchenpos.products.domain.Product; +import kitchenpos.products.application.dto.ProductRequest; +import kitchenpos.products.tobe.domain.Product; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.net.URI; import java.util.List; @@ -19,10 +26,10 @@ public ProductRestController(final ProductService productService) { } @PostMapping - public ResponseEntity create(@RequestBody final Product request) { + public ResponseEntity create(@RequestBody final ProductRequest request) { final Product response = productService.create(request); return ResponseEntity.created(URI.create("/api/products/" + response.getId())) - .body(response); + .body(response); } @PutMapping("/{productId}/price") From 2c6834492f9caf39e71ee58bf671db58a513548a Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:05:30 +0900 Subject: [PATCH 24/50] =?UTF-8?q?feat(Fixtures):=20Product=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/kitchenpos/Fixtures.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/test/java/kitchenpos/Fixtures.java b/src/test/java/kitchenpos/Fixtures.java index a17a54ab8..d4a5657ce 100644 --- a/src/test/java/kitchenpos/Fixtures.java +++ b/src/test/java/kitchenpos/Fixtures.java @@ -4,7 +4,10 @@ import kitchenpos.menus.domain.Menu; import kitchenpos.menus.domain.MenuGroup; import kitchenpos.menus.domain.MenuProduct; -import kitchenpos.products.domain.Product; +import kitchenpos.products.application.FakePurgomalumClient; +import kitchenpos.products.tobe.domain.DisplayedName; +import kitchenpos.products.tobe.domain.Product; +import kitchenpos.products.tobe.domain.ProductPrice; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -118,10 +121,11 @@ public static Product product() { } public static Product product(final String name, final long price) { - final Product product = new Product(); - product.setId(UUID.randomUUID()); - product.setName(name); - product.setPrice(BigDecimal.valueOf(price)); + final Product product = new Product( + UUID.randomUUID(), + new ProductPrice(BigDecimal.valueOf(price)), + new DisplayedName(name, new FakePurgomalumClient()) + ); return product; } } From eca26f5f1d09a8d183829cfe6e25780806edbe6c Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:10:22 +0900 Subject: [PATCH 25/50] =?UTF-8?q?feat(MenuProduct):=20multiply=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/application/MenuService.java | 53 +++++++++++-------- .../products/tobe/domain/ProductPrice.java | 4 ++ .../menus/application/MenuServiceTest.java | 1 + 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/main/java/kitchenpos/menus/application/MenuService.java b/src/main/java/kitchenpos/menus/application/MenuService.java index f6dea396f..d418cfba4 100644 --- a/src/main/java/kitchenpos/menus/application/MenuService.java +++ b/src/main/java/kitchenpos/menus/application/MenuService.java @@ -1,13 +1,22 @@ package kitchenpos.menus.application; -import kitchenpos.menus.domain.*; +import kitchenpos.menus.domain.Menu; +import kitchenpos.menus.domain.MenuGroup; +import kitchenpos.menus.domain.MenuGroupRepository; +import kitchenpos.menus.domain.MenuProduct; +import kitchenpos.menus.domain.MenuRepository; import kitchenpos.products.domain.ProductRepository; import kitchenpos.products.infra.Profanities; +import kitchenpos.products.tobe.domain.Product; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.UUID; import java.util.stream.Collectors; @Service @@ -18,10 +27,10 @@ public class MenuService { private final Profanities purgomalumClient; public MenuService( - final MenuRepository menuRepository, - final MenuGroupRepository menuGroupRepository, - final ProductRepository productRepository, - final Profanities purgomalumClient + final MenuRepository menuRepository, + final MenuGroupRepository menuGroupRepository, + final ProductRepository productRepository, + final Profanities purgomalumClient ) { this.menuRepository = menuRepository; this.menuGroupRepository = menuGroupRepository; @@ -36,15 +45,15 @@ public Menu create(final Menu request) { throw new IllegalArgumentException(); } final MenuGroup menuGroup = menuGroupRepository.findById(request.getMenuGroupId()) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); final List menuProductRequests = request.getMenuProducts(); if (Objects.isNull(menuProductRequests) || menuProductRequests.isEmpty()) { throw new IllegalArgumentException(); } final List products = productRepository.findAllByIdIn( - menuProductRequests.stream() - .map(MenuProduct::getProductId) - .collect(Collectors.toList()) + menuProductRequests.stream() + .map(MenuProduct::getProductId) + .collect(Collectors.toList()) ); if (products.size() != menuProductRequests.size()) { throw new IllegalArgumentException(); @@ -57,10 +66,10 @@ public Menu create(final Menu request) { throw new IllegalArgumentException(); } final Product product = productRepository.findById(menuProductRequest.getProductId()) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); sum = sum.add( - product.getPrice() - .multiply(BigDecimal.valueOf(quantity)) + product.getPrice() + .multiply(BigDecimal.valueOf(quantity)) ); final MenuProduct menuProduct = new MenuProduct(); menuProduct.setProduct(product); @@ -91,13 +100,13 @@ public Menu changePrice(final UUID menuId, final Menu request) { throw new IllegalArgumentException(); } final Menu menu = menuRepository.findById(menuId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); BigDecimal sum = BigDecimal.ZERO; for (final MenuProduct menuProduct : menu.getMenuProducts()) { sum = sum.add( - menuProduct.getProduct() - .getPrice() - .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) + menuProduct.getProduct() + .getPrice() + .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) ); } if (price.compareTo(sum) > 0) { @@ -110,13 +119,13 @@ public Menu changePrice(final UUID menuId, final Menu request) { @Transactional public Menu display(final UUID menuId) { final Menu menu = menuRepository.findById(menuId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); BigDecimal sum = BigDecimal.ZERO; for (final MenuProduct menuProduct : menu.getMenuProducts()) { sum = sum.add( - menuProduct.getProduct() - .getPrice() - .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) + menuProduct.getProduct() + .getPrice() + .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) ); } if (menu.getPrice().compareTo(sum) > 0) { @@ -129,7 +138,7 @@ public Menu display(final UUID menuId) { @Transactional public Menu hide(final UUID menuId) { final Menu menu = menuRepository.findById(menuId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); menu.setDisplayed(false); return menu; } diff --git a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java index f91745942..663b2de21 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java +++ b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java @@ -23,6 +23,10 @@ public ProductPrice() { this.price = null; } + public BigDecimal multiply(BigDecimal price) { + return this.price.multiply(price); + } + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/test/java/kitchenpos/menus/application/MenuServiceTest.java b/src/test/java/kitchenpos/menus/application/MenuServiceTest.java index ce9475eaf..9e527a3b8 100644 --- a/src/test/java/kitchenpos/menus/application/MenuServiceTest.java +++ b/src/test/java/kitchenpos/menus/application/MenuServiceTest.java @@ -8,6 +8,7 @@ import kitchenpos.products.application.InMemoryProductRepository; import kitchenpos.products.domain.ProductRepository; import kitchenpos.products.infra.Profanities; +import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From 3bfcfec9a040d1103611c7f27551272cd22c2e0b Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:16:19 +0900 Subject: [PATCH 26/50] =?UTF-8?q?refactor(ProductService):=20changePrice?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/menus/domain/MenuProduct.java | 20 ++++++++++++++----- .../products/application/ProductService.java | 9 ++------- .../products/tobe/domain/Product.java | 20 ++++++++++++++++++- .../products/ui/ProductRestController.java | 2 +- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/main/java/kitchenpos/menus/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/domain/MenuProduct.java index 2836096e6..fb8cdfe0f 100644 --- a/src/main/java/kitchenpos/menus/domain/MenuProduct.java +++ b/src/main/java/kitchenpos/menus/domain/MenuProduct.java @@ -1,8 +1,18 @@ package kitchenpos.menus.domain; -import kitchenpos.products.domain.Product; -import javax.persistence.*; +import kitchenpos.products.tobe.domain.Product; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; import java.util.UUID; @Table(name = "menu_product") @@ -15,9 +25,9 @@ public class MenuProduct { @ManyToOne(optional = false) @JoinColumn( - name = "product_id", - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_menu_product_to_product") + name = "product_id", + columnDefinition = "binary(16)", + foreignKey = @ForeignKey(name = "fk_menu_product_to_product") ) private Product product; diff --git a/src/main/java/kitchenpos/products/application/ProductService.java b/src/main/java/kitchenpos/products/application/ProductService.java index 8cfc99dc8..caf137794 100644 --- a/src/main/java/kitchenpos/products/application/ProductService.java +++ b/src/main/java/kitchenpos/products/application/ProductService.java @@ -15,7 +15,6 @@ import java.math.BigDecimal; import java.util.List; import java.util.NoSuchElementException; -import java.util.Objects; import java.util.UUID; @Service @@ -42,14 +41,10 @@ public Product create(final ProductRequest request) { } @Transactional - public Product changePrice(final UUID productId, final Product request) { - final BigDecimal price = request.getPrice(); - if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) { - throw new IllegalArgumentException(); - } + public Product changePrice(final UUID productId, final ProductRequest request) { final Product product = productRepository.findById(productId) .orElseThrow(NoSuchElementException::new); - product.setPrice(price); + product.changePrice(new ProductPrice(request.getPrice())); final List menus = menuRepository.findAllByProductId(productId); for (final Menu menu : menus) { BigDecimal sum = BigDecimal.ZERO; diff --git a/src/main/java/kitchenpos/products/tobe/domain/Product.java b/src/main/java/kitchenpos/products/tobe/domain/Product.java index 060fb3681..61115f851 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Product.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Product.java @@ -20,12 +20,18 @@ public class Product { @Embedded private DisplayedName name; + public Product(final UUID id, final ProductPrice price, final DisplayedName name) { + this.id = id; + this.price = price; + this.name = name; + } + public Product(final ProductPrice price, final DisplayedName name) { this.price = price; this.name = name; } - protected Product() { + public Product() { } public UUID getId() { @@ -40,6 +46,18 @@ public DisplayedName getName() { return name; } + public void setId(final UUID id) { + this.id = id; + } + + public void setPrice(final ProductPrice price) { + this.price = price; + } + + public void setName(final DisplayedName name) { + this.name = name; + } + public void changePrice(final ProductPrice price) { this.price = price; } diff --git a/src/main/java/kitchenpos/products/ui/ProductRestController.java b/src/main/java/kitchenpos/products/ui/ProductRestController.java index 312da8cb9..9d00d8c83 100644 --- a/src/main/java/kitchenpos/products/ui/ProductRestController.java +++ b/src/main/java/kitchenpos/products/ui/ProductRestController.java @@ -33,7 +33,7 @@ public ResponseEntity create(@RequestBody final ProductRequest request) } @PutMapping("/{productId}/price") - public ResponseEntity changePrice(@PathVariable final UUID productId, @RequestBody final Product request) { + public ResponseEntity changePrice(@PathVariable final UUID productId, @RequestBody final ProductRequest request) { return ResponseEntity.ok(productService.changePrice(productId, request)); } From ed4067ec2a59efa9ecd864949bd00e21ddbf1116 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:16:37 +0900 Subject: [PATCH 27/50] =?UTF-8?q?refactor(ProductRequest):=20ProductReques?= =?UTF-8?q?t=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/ProductRequest.java | 8 +++++++ .../InMemoryProductRepository.java | 2 +- .../application/ProductServiceTest.java | 24 ++++++++++--------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/kitchenpos/products/application/dto/ProductRequest.java b/src/main/java/kitchenpos/products/application/dto/ProductRequest.java index 5d1a327c8..26993cd5a 100644 --- a/src/main/java/kitchenpos/products/application/dto/ProductRequest.java +++ b/src/main/java/kitchenpos/products/application/dto/ProductRequest.java @@ -13,4 +13,12 @@ public BigDecimal getPrice() { public String getName() { return name; } + + public void setPrice(final BigDecimal price) { + this.price = price; + } + + public void setName(final String name) { + this.name = name; + } } diff --git a/src/test/java/kitchenpos/products/application/InMemoryProductRepository.java b/src/test/java/kitchenpos/products/application/InMemoryProductRepository.java index 2fd78e96d..aeec3ddb7 100644 --- a/src/test/java/kitchenpos/products/application/InMemoryProductRepository.java +++ b/src/test/java/kitchenpos/products/application/InMemoryProductRepository.java @@ -1,7 +1,7 @@ package kitchenpos.products.application; -import kitchenpos.products.domain.Product; import kitchenpos.products.domain.ProductRepository; +import kitchenpos.products.tobe.domain.Product; import java.util.*; import java.util.stream.Collectors; diff --git a/src/test/java/kitchenpos/products/application/ProductServiceTest.java b/src/test/java/kitchenpos/products/application/ProductServiceTest.java index a4c448cb2..bc8a6c8da 100644 --- a/src/test/java/kitchenpos/products/application/ProductServiceTest.java +++ b/src/test/java/kitchenpos/products/application/ProductServiceTest.java @@ -3,8 +3,10 @@ import kitchenpos.menus.application.InMemoryMenuRepository; import kitchenpos.menus.domain.Menu; import kitchenpos.menus.domain.MenuRepository; +import kitchenpos.products.application.dto.ProductRequest; import kitchenpos.products.domain.ProductRepository; import kitchenpos.products.infra.Profanities; +import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -38,7 +40,7 @@ void setUp() { @DisplayName("상품을 등록할 수 있다.") @Test void create() { - final Product expected = createProductRequest("후라이드", 16_000L); + final ProductRequest expected = createProductRequest("후라이드", 16_000L); final Product actual = productService.create(expected); assertThat(actual).isNotNull(); assertAll( @@ -53,7 +55,7 @@ void create() { @NullSource @ParameterizedTest void create(final BigDecimal price) { - final Product expected = createProductRequest("후라이드", price); + final ProductRequest expected = createProductRequest("후라이드", price); assertThatThrownBy(() -> productService.create(expected)) .isInstanceOf(IllegalArgumentException.class); } @@ -63,7 +65,7 @@ void create(final BigDecimal price) { @NullSource @ParameterizedTest void create(final String name) { - final Product expected = createProductRequest(name, 16_000L); + final ProductRequest expected = createProductRequest(name, 16_000L); assertThatThrownBy(() -> productService.create(expected)) .isInstanceOf(IllegalArgumentException.class); } @@ -72,7 +74,7 @@ void create(final String name) { @Test void changePrice() { final UUID productId = productRepository.save(product("후라이드", 16_000L)).getId(); - final Product expected = changePriceRequest(15_000L); + final ProductRequest expected = changePriceRequest(15_000L); final Product actual = productService.changePrice(productId, expected); assertThat(actual.getPrice()).isEqualTo(expected.getPrice()); } @@ -83,7 +85,7 @@ void changePrice() { @ParameterizedTest void changePrice(final BigDecimal price) { final UUID productId = productRepository.save(product("후라이드", 16_000L)).getId(); - final Product expected = changePriceRequest(price); + final ProductRequest expected = changePriceRequest(price); assertThatThrownBy(() -> productService.changePrice(productId, expected)) .isInstanceOf(IllegalArgumentException.class); } @@ -106,23 +108,23 @@ void findAll() { assertThat(actual).hasSize(2); } - private Product createProductRequest(final String name, final long price) { + private ProductRequest createProductRequest(final String name, final long price) { return createProductRequest(name, BigDecimal.valueOf(price)); } - private Product createProductRequest(final String name, final BigDecimal price) { - final Product product = new Product(); + private ProductRequest createProductRequest(final String name, final BigDecimal price) { + final ProductRequest product = new ProductRequest(); product.setName(name); product.setPrice(price); return product; } - private Product changePriceRequest(final long price) { + private ProductRequest changePriceRequest(final long price) { return changePriceRequest(BigDecimal.valueOf(price)); } - private Product changePriceRequest(final BigDecimal price) { - final Product product = new Product(); + private ProductRequest changePriceRequest(final BigDecimal price) { + final ProductRequest product = new ProductRequest(); product.setPrice(price); return product; } From 85a84f579f546b73b2d13d388c617c55827d3cdc Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:33:29 +0900 Subject: [PATCH 28/50] =?UTF-8?q?refactor(Menu):=20tobe=EC=9D=98=20Menu=20?= =?UTF-8?q?Entity=EB=A5=BC=20Jpa=EC=9D=98=20Entity=EB=A1=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/tobe/domain/DisplayedName.java | 10 +- .../kitchenpos/menus/tobe/domain/Menu.java | 97 ++++++++++++++++++- .../menus/tobe/domain/MenuGroup.java | 4 - .../kitchenpos/menus/tobe/domain/Price.java | 10 +- 4 files changed, 114 insertions(+), 7 deletions(-) delete mode 100644 src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java index 3451a2a6c..04706a87e 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java @@ -1,14 +1,18 @@ package kitchenpos.menus.tobe.domain; +import javax.persistence.Column; +import javax.persistence.Embeddable; import java.util.Objects; +@Embeddable class DisplayedName { private static final String EMPTY_NAME_MESSAGE = "이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "이름에 비속어가 포함될 수 없습니다."; + @Column(name = "name", nullable = false) private final String name; - DisplayedName(final String name, final Profanity profanity) { + DisplayedName(final String name, final Profanity profanity) { if (null == name || name.isBlank()) { throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); } @@ -18,6 +22,10 @@ class DisplayedName { this.name = name; } + protected DisplayedName() { + this.name = null; + } + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 4ab69dfbb..5b3094234 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -1,13 +1,57 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.menus.domain.MenuGroup; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.util.List; +import java.util.UUID; + +@Table(name = "menu") +@Entity public class Menu { private static final String CAN_NOT_DISPLAY_MESSAGE = "메뉴의 가격은 상품 가격의 합보다 작다면 전시할 수 없습니다."; + + @Column(name = "id", columnDefinition = "binary(16)") + @Id + private UUID id; + + @Embedded private Price price; + + @Embedded private DisplayedName name; - private MenuProduct menuProduct; + + @ManyToOne(optional = false) + @JoinColumn( + name = "menu_group_id", + columnDefinition = "binary(16)", + foreignKey = @ForeignKey(name = "fk_menu_to_menu_group") + ) private MenuGroup menuGroup; private boolean displayed; + @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinColumn( + name = "menu_id", + nullable = false, + columnDefinition = "binary(16)", + foreignKey = @ForeignKey(name = "fk_menu_product_to_menu") + ) + private List menuProducts; + + @Transient + private UUID menuGroupId; + public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct, final MenuGroup menuGroup) { decideDisplay(menuProduct, price); this.price = price; @@ -16,10 +60,61 @@ public Menu(final Price price, final DisplayedName name, final MenuProduct menuP this.menuGroup = menuGroup; } + public Menu() { + } + + public UUID getId() { + return id; + } + + public void setId(final UUID id) { + this.id = id; + } + public Price getPrice() { return price; } + public void setPrice(final Price price) { + this.price = price; + } + + public DisplayedName getName() { + return name; + } + + public void setName(final DisplayedName name) { + this.name = name; + } + + public MenuGroup getMenuGroup() { + return menuGroup; + } + + public void setMenuGroup(final MenuGroup menuGroup) { + this.menuGroup = menuGroup; + } + + public void setDisplayed(final boolean displayed) { + this.displayed = displayed; + } + + public MenuProduct getMenuProduct() { + return menuProduct; + } + + public void setMenuProduct(final MenuProduct menuProduct) { + this.menuProduct = menuProduct; + } + + public UUID getMenuGroupId() { + return menuGroupId; + } + + public void setMenuGroupId(final UUID menuGroupId) { + this.menuGroupId = menuGroupId; + } + public void changePrice(final Price price) { decideDisplay(this.menuProduct, price); this.price = price; diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java deleted file mode 100644 index 862fb8862..000000000 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuGroup.java +++ /dev/null @@ -1,4 +0,0 @@ -package kitchenpos.menus.tobe.domain; - -class MenuGroup { -} diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Price.java b/src/main/java/kitchenpos/menus/tobe/domain/Price.java index d7c0a11bd..533954396 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Price.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Price.java @@ -1,12 +1,16 @@ package kitchenpos.menus.tobe.domain; +import javax.persistence.Column; +import javax.persistence.Embeddable; import java.math.BigDecimal; import java.util.Objects; -class Price implements Comparable { +@Embeddable +public class Price implements Comparable { private static final String EMPTY_NAME_MESSAGE = "가격은 비어있을 수 없습니다."; private static final String INVALID_PRICE_MESSAGE = "가격은 0보다 크거다 같아야 합니다."; + @Column(name = "price", nullable = false) private final BigDecimal price; Price(final BigDecimal price) { @@ -19,6 +23,10 @@ class Price implements Comparable { this.price = price; } + protected Price() { + this.price = null; + } + public Price multiply(long quantity) { return new Price(price.multiply(BigDecimal.valueOf(quantity))); } From 49329fbe43f96b10d56f66eb903d0ab3a6c9d6c6 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 17 Oct 2022 21:47:41 +0900 Subject: [PATCH 29/50] =?UTF-8?q?refactor(MenuProduct):=20domain=EC=9D=98?= =?UTF-8?q?=20MenuProduct=EB=A5=BC=20Jpa=EC=9D=98=20Entity=EB=A1=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/tobe/domain/MenuProduct.java | 44 ++++++++++++++++--- .../kitchenpos/menus/tobe/domain/Product.java | 19 -------- .../products/tobe/domain/Product.java | 11 ++++- .../menus/tobe/domain/MenuProductTest.java | 3 +- .../menus/tobe/domain/MenuTest.java | 12 ++--- 5 files changed, 58 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/kitchenpos/menus/tobe/domain/Product.java diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java index ed32613d5..ea4c7221a 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java @@ -1,23 +1,57 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.products.tobe.domain.Product; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.math.BigDecimal; +import java.util.UUID; + +@Table(name = "menu_product") +@Entity public class MenuProduct { private static final String LESS_THAN_ZERO_MESSAGE = "수량은 0보다 작을 수 없습니다."; - private long quantity; - private DisplayedName name; + @Column(name = "seq") + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + private Long seq; + + @ManyToOne(optional = false) + @JoinColumn( + name = "product_id", + columnDefinition = "binary(16)", + foreignKey = @ForeignKey(name = "fk_menu_product_to_product") + ) private Product product; - public MenuProduct(final long quantity, final DisplayedName name, final Product product) { + @Column(name = "quantity", nullable = false) + private long quantity; + + @Transient + private UUID productId; + + public MenuProduct(final long quantity, final Product product) { if (quantity < 0) { new IllegalArgumentException(LESS_THAN_ZERO_MESSAGE); } this.quantity = quantity; - this.name = name; this.product = product; } + protected MenuProduct() { + } + public Price getSumOfPrice() { - return product.getPrice().multiply(quantity); + return new Price(product.getPrice().multiply(BigDecimal.valueOf(quantity))); } public boolean lessThan(final Price price) { diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Product.java b/src/main/java/kitchenpos/menus/tobe/domain/Product.java deleted file mode 100644 index 88d39fcd6..000000000 --- a/src/main/java/kitchenpos/menus/tobe/domain/Product.java +++ /dev/null @@ -1,19 +0,0 @@ -package kitchenpos.menus.tobe.domain; - -import java.math.BigDecimal; - -class Product { - private Price price; - - public Product(final Price price) { - this.price = price; - } - - public Product(final BigDecimal price) { - this(new Price(price)); - } - - public Price getPrice() { - return price; - } -} diff --git a/src/main/java/kitchenpos/products/tobe/domain/Product.java b/src/main/java/kitchenpos/products/tobe/domain/Product.java index 61115f851..bf094331f 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Product.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Product.java @@ -5,6 +5,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; +import java.math.BigDecimal; import java.util.UUID; @Table(name = "product") @@ -31,7 +32,15 @@ public Product(final ProductPrice price, final DisplayedName name) { this.name = name; } - public Product() { + public Product(final ProductPrice price) { + this.price = price; + } + + public Product(BigDecimal price) { + this(new ProductPrice(price)); + } + + protected Product() { } public UUID getId() { diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java index c0dcc5738..78304346d 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuProductTest.java @@ -1,5 +1,6 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -19,7 +20,7 @@ class MenuProductTest { @ValueSource(longs = {0L, 1L}) void moreThanZeroAndEqualsQuantity(final long quantity) { final Product product = new Product(BigDecimal.ONE); - assertThatCode(() -> new MenuProduct(quantity, new DisplayedName("양념치킨", new FakeProfanity()), product)) + assertThatCode(() -> new MenuProduct(quantity, product)) .doesNotThrowAnyException(); } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index 163c7b1fd..c6ea27205 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -1,5 +1,7 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.menus.domain.MenuGroup; +import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -25,7 +27,7 @@ class MenuTest { void construct() { final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(6L))); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); final Menu menu = new Menu(price, name, menuProduct, new MenuGroup()); menu.changePrice(new Price(BigDecimal.ONE)); @@ -39,7 +41,7 @@ void construct() { void greaterThanAndEqualsMenuProductPriceSum(final long productPrice) { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(productPrice))); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(productPrice))); assertThatCode(() -> new Menu(menuPrice, name, menuProduct, new MenuGroup())) .doesNotThrowAnyException(); @@ -50,7 +52,7 @@ void greaterThanAndEqualsMenuProductPriceSum(final long productPrice) { void consistOfMenuGroup() { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(6L))); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); final MenuGroup menuGroup = new MenuGroup(); assertThatCode(() -> new Menu(menuPrice, name, menuProduct, menuGroup)) @@ -62,7 +64,7 @@ void consistOfMenuGroup() { void displayed() { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(6L))); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); final MenuGroup menuGroup = new MenuGroup(); final Menu menu = new Menu(menuPrice, name, menuProduct, menuGroup); @@ -80,7 +82,7 @@ void displayOffWithInvalidPrice() { final Price menuPrice = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new DisplayedName("양념치킨", new FakeProfanity()), new Product(BigDecimal.valueOf(4L))); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(4L))); final MenuGroup menuGroup = new MenuGroup(); final Menu menu = new Menu(menuPrice, name, menuProduct, menuGroup); From e41eed5f8bb8751f0cf7d3450431acb999bff693 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 20 Oct 2022 21:04:38 +0900 Subject: [PATCH 30/50] =?UTF-8?q?refactor(common):=20Price,=20DisplayedNam?= =?UTF-8?q?e,=20Profanities=20=EA=B3=B5=ED=86=B5=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/DefaultPurgomalumClient.java | 2 +- .../infra/Profanities.java | 2 +- .../domain => common/vo}/DisplayedName.java | 14 ++++-- .../tobe/domain => common/vo}/Price.java | 12 +++++- .../menus/tobe/domain/Profanity.java | 5 --- .../products/tobe/domain/DisplayedName.java | 43 ------------------- .../java/kitchenpos/common/FakeProfanity.java | 14 ++++++ .../menus/tobe/domain/DisplayedNameTest.java | 2 + .../menus/tobe/domain/FakeProfanity.java | 12 ------ .../menus/tobe/domain/PriceTest.java | 1 + .../application/FakePurgomalumClient.java | 4 +- .../tobe/domain/DisplayedNameTest.java | 12 +++--- .../products/tobe/domain/FakeProfanities.java | 14 ------ 13 files changed, 48 insertions(+), 89 deletions(-) rename src/main/java/kitchenpos/{products => common}/infra/DefaultPurgomalumClient.java (96%) rename src/main/java/kitchenpos/{products => common}/infra/Profanities.java (69%) rename src/main/java/kitchenpos/{menus/tobe/domain => common/vo}/DisplayedName.java (78%) rename src/main/java/kitchenpos/{menus/tobe/domain => common/vo}/Price.java (85%) delete mode 100644 src/main/java/kitchenpos/menus/tobe/domain/Profanity.java delete mode 100644 src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java create mode 100644 src/test/java/kitchenpos/common/FakeProfanity.java delete mode 100644 src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java delete mode 100644 src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java diff --git a/src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java b/src/main/java/kitchenpos/common/infra/DefaultPurgomalumClient.java similarity index 96% rename from src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java rename to src/main/java/kitchenpos/common/infra/DefaultPurgomalumClient.java index 945177a79..d1b41fba0 100644 --- a/src/main/java/kitchenpos/products/infra/DefaultPurgomalumClient.java +++ b/src/main/java/kitchenpos/common/infra/DefaultPurgomalumClient.java @@ -1,4 +1,4 @@ -package kitchenpos.products.infra; +package kitchenpos.common.infra; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.stereotype.Component; diff --git a/src/main/java/kitchenpos/products/infra/Profanities.java b/src/main/java/kitchenpos/common/infra/Profanities.java similarity index 69% rename from src/main/java/kitchenpos/products/infra/Profanities.java rename to src/main/java/kitchenpos/common/infra/Profanities.java index 93739ef5b..5e2c36e11 100644 --- a/src/main/java/kitchenpos/products/infra/Profanities.java +++ b/src/main/java/kitchenpos/common/infra/Profanities.java @@ -1,4 +1,4 @@ -package kitchenpos.products.infra; +package kitchenpos.common.infra; public interface Profanities { boolean containsProfanity(String text); diff --git a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/common/vo/DisplayedName.java similarity index 78% rename from src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java rename to src/main/java/kitchenpos/common/vo/DisplayedName.java index 04706a87e..4a39fb5e4 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/DisplayedName.java +++ b/src/main/java/kitchenpos/common/vo/DisplayedName.java @@ -1,22 +1,24 @@ -package kitchenpos.menus.tobe.domain; +package kitchenpos.common.vo; + +import kitchenpos.common.infra.Profanities; import javax.persistence.Column; import javax.persistence.Embeddable; import java.util.Objects; @Embeddable -class DisplayedName { +public class DisplayedName { private static final String EMPTY_NAME_MESSAGE = "이름은 비어있을 수 없습니다."; private static final String CONTAIN_PROFANITY_MESSAGE = "이름에 비속어가 포함될 수 없습니다."; @Column(name = "name", nullable = false) private final String name; - DisplayedName(final String name, final Profanity profanity) { + public DisplayedName(final String name, final Profanities profanities) { if (null == name || name.isBlank()) { throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); } - if (profanity.isContains(name)) { + if (profanities.containsProfanity(name)) { throw new IllegalArgumentException(CONTAIN_PROFANITY_MESSAGE); } this.name = name; @@ -26,6 +28,10 @@ protected DisplayedName() { this.name = null; } + public String getName() { + return name; + } + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Price.java b/src/main/java/kitchenpos/common/vo/Price.java similarity index 85% rename from src/main/java/kitchenpos/menus/tobe/domain/Price.java rename to src/main/java/kitchenpos/common/vo/Price.java index 533954396..893254184 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Price.java +++ b/src/main/java/kitchenpos/common/vo/Price.java @@ -1,4 +1,4 @@ -package kitchenpos.menus.tobe.domain; +package kitchenpos.common.vo; import javax.persistence.Column; import javax.persistence.Embeddable; @@ -13,7 +13,7 @@ public class Price implements Comparable { @Column(name = "price", nullable = false) private final BigDecimal price; - Price(final BigDecimal price) { + public Price(final BigDecimal price) { if (null == price) { throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); } @@ -27,6 +27,10 @@ protected Price() { this.price = null; } + public BigDecimal getPrice() { + return price; + } + public Price multiply(long quantity) { return new Price(price.multiply(BigDecimal.valueOf(quantity))); } @@ -48,4 +52,8 @@ public int hashCode() { public int compareTo(final Price o) { return price.subtract(o.price).intValue(); } + + public Price add(final Price price) { + return new Price(this.price.add(price.price)); + } } diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Profanity.java b/src/main/java/kitchenpos/menus/tobe/domain/Profanity.java deleted file mode 100644 index b72c233f3..000000000 --- a/src/main/java/kitchenpos/menus/tobe/domain/Profanity.java +++ /dev/null @@ -1,5 +0,0 @@ -package kitchenpos.menus.tobe.domain; - -interface Profanity { - boolean isContains(String name); -} diff --git a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java b/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java deleted file mode 100644 index da49a4eee..000000000 --- a/src/main/java/kitchenpos/products/tobe/domain/DisplayedName.java +++ /dev/null @@ -1,43 +0,0 @@ -package kitchenpos.products.tobe.domain; - -import kitchenpos.products.infra.Profanities; - -import javax.persistence.Column; -import javax.persistence.Embeddable; -import java.util.Objects; - -@Embeddable -public class DisplayedName { - private static final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; - private static final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; - - @Column(name = "name", nullable = false) - private final String name; - - public DisplayedName(final String name, final Profanities profanities) { - if (null == name || name.isBlank()) { - throw new IllegalArgumentException(EMPTY_NAME_MESSAGE); - } - if (profanities.containsProfanity(name)) { - throw new IllegalArgumentException(CONTAIN_PROFANITY_MESSAGE); - } - this.name = name; - } - - protected DisplayedName() { - this.name = null; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (null == o || getClass() != o.getClass()) return false; - final DisplayedName that = (DisplayedName) o; - return Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } -} diff --git a/src/test/java/kitchenpos/common/FakeProfanity.java b/src/test/java/kitchenpos/common/FakeProfanity.java new file mode 100644 index 000000000..f15748a20 --- /dev/null +++ b/src/test/java/kitchenpos/common/FakeProfanity.java @@ -0,0 +1,14 @@ +package kitchenpos.common; + +import kitchenpos.common.infra.Profanities; + +import java.util.List; + +public class FakeProfanity implements Profanities { + private final List values = List.of("damn"); + + @Override + public boolean containsProfanity(final String name) { + return values.contains(name); + } +} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java index 843b008cf..a0652d506 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/DisplayedNameTest.java @@ -1,5 +1,7 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java b/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java deleted file mode 100644 index 118416611..000000000 --- a/src/test/java/kitchenpos/menus/tobe/domain/FakeProfanity.java +++ /dev/null @@ -1,12 +0,0 @@ -package kitchenpos.menus.tobe.domain; - -import java.util.List; - -class FakeProfanity implements Profanity { - private final List values = List.of("damn"); - - @Override - public boolean isContains(final String name) { - return values.contains(name); - } -} diff --git a/src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java b/src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java index a781e524a..93bcdc3f1 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/PriceTest.java @@ -1,5 +1,6 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.common.vo.Price; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java b/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java index f10e034d8..49844ed51 100644 --- a/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java +++ b/src/test/java/kitchenpos/products/application/FakePurgomalumClient.java @@ -1,6 +1,6 @@ package kitchenpos.products.application; -import kitchenpos.products.infra.Profanities; +import kitchenpos.common.infra.Profanities; import java.util.Arrays; import java.util.List; @@ -15,6 +15,6 @@ public class FakePurgomalumClient implements Profanities { @Override public boolean containsProfanity(final String text) { return profanities.stream() - .anyMatch(profanity -> text.contains(profanity)); + .anyMatch(text::contains); } } diff --git a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java index e100542e4..386e8fb2b 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/DisplayedNameTest.java @@ -1,5 +1,7 @@ package kitchenpos.products.tobe.domain; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -8,13 +10,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; class DisplayedNameTest { - @DisplayName("상품 이름은 비어있을 수 없다.") + @DisplayName("이름은 비어있을 수 없다.") @NullAndEmptySource @ParameterizedTest void emptyName(final String name) { - final String EMPTY_NAME_MESSAGE = "상품 이름은 비어있을 수 없습니다."; + final String EMPTY_NAME_MESSAGE = "이름은 비어있을 수 없습니다."; - assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanities())) + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) .isInstanceOf(IllegalArgumentException.class) .hasMessage(EMPTY_NAME_MESSAGE); } @@ -22,10 +24,10 @@ void emptyName(final String name) { @DisplayName("상품 이름에 비속어가 포함될 수 없다.") @Test void registerWithProfanity() { - final String CONTAIN_PROFANITY_MESSAGE = "상품 이름에 비속어가 포함될 수 없습니다."; + final String CONTAIN_PROFANITY_MESSAGE = "이름에 비속어가 포함될 수 없습니다."; final String name = "damn"; - assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanities())) + assertThatThrownBy(() -> new DisplayedName(name, new FakeProfanity())) .isInstanceOf(IllegalArgumentException.class) .hasMessage(CONTAIN_PROFANITY_MESSAGE); } diff --git a/src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java b/src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java deleted file mode 100644 index e23d87b2a..000000000 --- a/src/test/java/kitchenpos/products/tobe/domain/FakeProfanities.java +++ /dev/null @@ -1,14 +0,0 @@ -package kitchenpos.products.tobe.domain; - -import kitchenpos.products.infra.Profanities; - -import java.util.List; - -class FakeProfanities implements Profanities { - private final List values = List.of("damn"); - - @Override - public boolean containsProfanity(final String text) { - return values.contains(text); - } -} From 354c270430fc528522fc6d89b2ad76d3a77cd352 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 20 Oct 2022 21:08:30 +0900 Subject: [PATCH 31/50] =?UTF-8?q?refactor(Menu,=20MenuProduct=20):=20tobe?= =?UTF-8?q?=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/application/OrderService.java | 51 ++++--- .../eatinorders/domain/OrderLineItem.java | 21 ++- .../menus/application/MenuService.java | 38 +++--- .../menus/domain/JpaMenuRepository.java | 1 + .../java/kitchenpos/menus/domain/Menu.java | 102 -------------- .../kitchenpos/menus/domain/MenuProduct.java | 74 ---------- .../menus/domain/MenuRepository.java | 2 + .../kitchenpos/menus/tobe/domain/Menu.java | 88 +++++++++--- .../menus/tobe/domain/MenuProduct.java | 38 +++++- .../menus/ui/MenuRestController.java | 10 +- .../application/InMemoryMenuRepository.java | 23 ++-- .../menus/application/MenuServiceTest.java | 128 ++++++++++-------- .../menus/tobe/domain/MenuTest.java | 14 +- 13 files changed, 272 insertions(+), 318 deletions(-) delete mode 100644 src/main/java/kitchenpos/menus/domain/Menu.java delete mode 100644 src/main/java/kitchenpos/menus/domain/MenuProduct.java diff --git a/src/main/java/kitchenpos/eatinorders/application/OrderService.java b/src/main/java/kitchenpos/eatinorders/application/OrderService.java index c20f52c7f..e0a87d305 100644 --- a/src/main/java/kitchenpos/eatinorders/application/OrderService.java +++ b/src/main/java/kitchenpos/eatinorders/application/OrderService.java @@ -1,15 +1,25 @@ package kitchenpos.eatinorders.application; import kitchenpos.deliveryorders.infra.KitchenridersClient; -import kitchenpos.eatinorders.domain.*; -import kitchenpos.menus.domain.Menu; +import kitchenpos.eatinorders.domain.Order; +import kitchenpos.eatinorders.domain.OrderLineItem; +import kitchenpos.eatinorders.domain.OrderRepository; +import kitchenpos.eatinorders.domain.OrderStatus; +import kitchenpos.eatinorders.domain.OrderTable; +import kitchenpos.eatinorders.domain.OrderTableRepository; +import kitchenpos.eatinorders.domain.OrderType; import kitchenpos.menus.domain.MenuRepository; +import kitchenpos.menus.tobe.domain.Menu; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.UUID; import java.util.stream.Collectors; @Service @@ -20,10 +30,10 @@ public class OrderService { private final KitchenridersClient kitchenridersClient; public OrderService( - final OrderRepository orderRepository, - final MenuRepository menuRepository, - final OrderTableRepository orderTableRepository, - final KitchenridersClient kitchenridersClient + final OrderRepository orderRepository, + final MenuRepository menuRepository, + final OrderTableRepository orderTableRepository, + final KitchenridersClient kitchenridersClient ) { this.orderRepository = orderRepository; this.menuRepository = menuRepository; @@ -42,9 +52,9 @@ public Order create(final Order request) { throw new IllegalArgumentException(); } final List menus = menuRepository.findAllByIdIn( - orderLineItemRequests.stream() - .map(OrderLineItem::getMenuId) - .collect(Collectors.toList()) + orderLineItemRequests.stream() + .map(OrderLineItem::getMenuId) + .collect(Collectors.toList()) ); if (menus.size() != orderLineItemRequests.size()) { throw new IllegalArgumentException(); @@ -58,11 +68,11 @@ public Order create(final Order request) { } } final Menu menu = menuRepository.findById(orderLineItemRequest.getMenuId()) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (!menu.isDisplayed()) { throw new IllegalStateException(); } - if (menu.getPrice().compareTo(orderLineItemRequest.getPrice()) != 0) { + if (menu.getPrice().getPrice().compareTo(orderLineItemRequest.getPrice()) != 0) { throw new IllegalArgumentException(); } final OrderLineItem orderLineItem = new OrderLineItem(); @@ -85,7 +95,7 @@ public Order create(final Order request) { } if (type == OrderType.EAT_IN) { final OrderTable orderTable = orderTableRepository.findById(request.getOrderTableId()) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (!orderTable.isOccupied()) { throw new IllegalStateException(); } @@ -97,7 +107,7 @@ public Order create(final Order request) { @Transactional public Order accept(final UUID orderId) { final Order order = orderRepository.findById(orderId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (order.getStatus() != OrderStatus.WAITING) { throw new IllegalStateException(); } @@ -105,8 +115,9 @@ public Order accept(final UUID orderId) { BigDecimal sum = BigDecimal.ZERO; for (final OrderLineItem orderLineItem : order.getOrderLineItems()) { sum = orderLineItem.getMenu() - .getPrice() - .multiply(BigDecimal.valueOf(orderLineItem.getQuantity())); + .getPrice() + .getPrice() + .multiply(BigDecimal.valueOf(orderLineItem.getQuantity())); } kitchenridersClient.requestDelivery(orderId, sum, order.getDeliveryAddress()); } @@ -117,7 +128,7 @@ public Order accept(final UUID orderId) { @Transactional public Order serve(final UUID orderId) { final Order order = orderRepository.findById(orderId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (order.getStatus() != OrderStatus.ACCEPTED) { throw new IllegalStateException(); } @@ -128,7 +139,7 @@ public Order serve(final UUID orderId) { @Transactional public Order startDelivery(final UUID orderId) { final Order order = orderRepository.findById(orderId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (order.getType() != OrderType.DELIVERY) { throw new IllegalStateException(); } @@ -142,7 +153,7 @@ public Order startDelivery(final UUID orderId) { @Transactional public Order completeDelivery(final UUID orderId) { final Order order = orderRepository.findById(orderId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (order.getStatus() != OrderStatus.DELIVERING) { throw new IllegalStateException(); } @@ -153,7 +164,7 @@ public Order completeDelivery(final UUID orderId) { @Transactional public Order complete(final UUID orderId) { final Order order = orderRepository.findById(orderId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); final OrderType type = order.getType(); final OrderStatus status = order.getStatus(); if (type == OrderType.DELIVERY) { diff --git a/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java b/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java index e1e037caf..12b8e02b5 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java +++ b/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java @@ -1,8 +1,17 @@ package kitchenpos.eatinorders.domain; -import kitchenpos.menus.domain.Menu; - -import javax.persistence.*; +import kitchenpos.menus.tobe.domain.Menu; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; import java.math.BigDecimal; import java.util.UUID; @@ -16,9 +25,9 @@ public class OrderLineItem { @ManyToOne(optional = false) @JoinColumn( - name = "menu_id", - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_order_line_item_to_menu") + name = "menu_id", + columnDefinition = "binary(16)", + foreignKey = @ForeignKey(name = "fk_order_line_item_to_menu") ) private Menu menu; diff --git a/src/main/java/kitchenpos/menus/application/MenuService.java b/src/main/java/kitchenpos/menus/application/MenuService.java index d418cfba4..3887d950f 100644 --- a/src/main/java/kitchenpos/menus/application/MenuService.java +++ b/src/main/java/kitchenpos/menus/application/MenuService.java @@ -1,12 +1,14 @@ package kitchenpos.menus.application; -import kitchenpos.menus.domain.Menu; +import kitchenpos.common.vo.DisplayedName; import kitchenpos.menus.domain.MenuGroup; import kitchenpos.menus.domain.MenuGroupRepository; -import kitchenpos.menus.domain.MenuProduct; import kitchenpos.menus.domain.MenuRepository; +import kitchenpos.menus.tobe.domain.Menu; +import kitchenpos.menus.tobe.domain.MenuProduct; +import kitchenpos.common.vo.Price; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.Profanities; +import kitchenpos.common.infra.Profanities; import kitchenpos.products.tobe.domain.Product; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +42,7 @@ public MenuService( @Transactional public Menu create(final Menu request) { - final BigDecimal price = request.getPrice(); + final BigDecimal price = request.getPrice().getPrice(); if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) { throw new IllegalArgumentException(); } @@ -69,7 +71,7 @@ public Menu create(final Menu request) { .orElseThrow(NoSuchElementException::new); sum = sum.add( product.getPrice() - .multiply(BigDecimal.valueOf(quantity)) + .multiply(quantity).getPrice() ); final MenuProduct menuProduct = new MenuProduct(); menuProduct.setProduct(product); @@ -79,23 +81,23 @@ public Menu create(final Menu request) { if (price.compareTo(sum) > 0) { throw new IllegalArgumentException(); } - final String name = request.getName(); + final String name = request.getName().getName(); if (Objects.isNull(name) || purgomalumClient.containsProfanity(name)) { throw new IllegalArgumentException(); } - final Menu menu = new Menu(); - menu.setId(UUID.randomUUID()); - menu.setName(name); - menu.setPrice(price); - menu.setMenuGroup(menuGroup); - menu.setDisplayed(request.isDisplayed()); - menu.setMenuProducts(menuProducts); + final Menu menu = new Menu( + UUID.randomUUID(), + new Price(price), + new DisplayedName(name, purgomalumClient), + request.isDisplayed(), + menuProducts + ); return menuRepository.save(menu); } @Transactional public Menu changePrice(final UUID menuId, final Menu request) { - final BigDecimal price = request.getPrice(); + final BigDecimal price = request.getPrice().getPrice(); if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) { throw new IllegalArgumentException(); } @@ -106,13 +108,13 @@ public Menu changePrice(final UUID menuId, final Menu request) { sum = sum.add( menuProduct.getProduct() .getPrice() - .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) + .multiply(menuProduct.getQuantity()).getPrice() ); } if (price.compareTo(sum) > 0) { throw new IllegalArgumentException(); } - menu.setPrice(price); + menu.changePrice(new Price(price)); return menu; } @@ -125,10 +127,10 @@ public Menu display(final UUID menuId) { sum = sum.add( menuProduct.getProduct() .getPrice() - .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) + .multiply(menuProduct.getQuantity()).getPrice() ); } - if (menu.getPrice().compareTo(sum) > 0) { + if (menu.getPrice().getPrice().compareTo(sum) > 0) { throw new IllegalStateException(); } menu.setDisplayed(true); diff --git a/src/main/java/kitchenpos/menus/domain/JpaMenuRepository.java b/src/main/java/kitchenpos/menus/domain/JpaMenuRepository.java index 796499c30..1673ba615 100644 --- a/src/main/java/kitchenpos/menus/domain/JpaMenuRepository.java +++ b/src/main/java/kitchenpos/menus/domain/JpaMenuRepository.java @@ -1,5 +1,6 @@ package kitchenpos.menus.domain; +import kitchenpos.menus.tobe.domain.Menu; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/kitchenpos/menus/domain/Menu.java b/src/main/java/kitchenpos/menus/domain/Menu.java deleted file mode 100644 index e923a6e5d..000000000 --- a/src/main/java/kitchenpos/menus/domain/Menu.java +++ /dev/null @@ -1,102 +0,0 @@ -package kitchenpos.menus.domain; - -import javax.persistence.*; -import java.math.BigDecimal; -import java.util.List; -import java.util.UUID; - -@Table(name = "menu") -@Entity -public class Menu { - @Column(name = "id", columnDefinition = "binary(16)") - @Id - private UUID id; - - @Column(name = "name", nullable = false) - private String name; - - @Column(name = "price", nullable = false) - private BigDecimal price; - - @ManyToOne(optional = false) - @JoinColumn( - name = "menu_group_id", - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_menu_to_menu_group") - ) - private MenuGroup menuGroup; - - @Column(name = "displayed", nullable = false) - private boolean displayed; - - @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) - @JoinColumn( - name = "menu_id", - nullable = false, - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_menu_product_to_menu") - ) - private List menuProducts; - - @Transient - private UUID menuGroupId; - - public Menu() { - } - - public UUID getId() { - return id; - } - - public void setId(final UUID id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(final BigDecimal price) { - this.price = price; - } - - public MenuGroup getMenuGroup() { - return menuGroup; - } - - public void setMenuGroup(final MenuGroup menuGroup) { - this.menuGroup = menuGroup; - } - - public boolean isDisplayed() { - return displayed; - } - - public void setDisplayed(final boolean displayed) { - this.displayed = displayed; - } - - public List getMenuProducts() { - return menuProducts; - } - - public void setMenuProducts(final List menuProducts) { - this.menuProducts = menuProducts; - } - - public UUID getMenuGroupId() { - return menuGroupId; - } - - public void setMenuGroupId(final UUID menuGroupId) { - this.menuGroupId = menuGroupId; - } -} diff --git a/src/main/java/kitchenpos/menus/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/domain/MenuProduct.java deleted file mode 100644 index fb8cdfe0f..000000000 --- a/src/main/java/kitchenpos/menus/domain/MenuProduct.java +++ /dev/null @@ -1,74 +0,0 @@ -package kitchenpos.menus.domain; - - -import kitchenpos.products.tobe.domain.Product; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.ForeignKey; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.util.UUID; - -@Table(name = "menu_product") -@Entity -public class MenuProduct { - @Column(name = "seq") - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Id - private Long seq; - - @ManyToOne(optional = false) - @JoinColumn( - name = "product_id", - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_menu_product_to_product") - ) - private Product product; - - @Column(name = "quantity", nullable = false) - private long quantity; - - @Transient - private UUID productId; - - public MenuProduct() { - } - - public Long getSeq() { - return seq; - } - - public void setSeq(final Long seq) { - this.seq = seq; - } - - public Product getProduct() { - return product; - } - - public void setProduct(final Product product) { - this.product = product; - } - - public long getQuantity() { - return quantity; - } - - public void setQuantity(final long quantity) { - this.quantity = quantity; - } - - public UUID getProductId() { - return productId; - } - - public void setProductId(final UUID productId) { - this.productId = productId; - } -} diff --git a/src/main/java/kitchenpos/menus/domain/MenuRepository.java b/src/main/java/kitchenpos/menus/domain/MenuRepository.java index 5fbaab864..ea4437b76 100644 --- a/src/main/java/kitchenpos/menus/domain/MenuRepository.java +++ b/src/main/java/kitchenpos/menus/domain/MenuRepository.java @@ -1,5 +1,7 @@ package kitchenpos.menus.domain; +import kitchenpos.menus.tobe.domain.Menu; + import java.util.List; import java.util.Optional; import java.util.UUID; diff --git a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java index 5b3094234..cf2ca2bd8 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/Menu.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/Menu.java @@ -1,5 +1,7 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.common.vo.Price; import kitchenpos.menus.domain.MenuGroup; import javax.persistence.CascadeType; @@ -13,6 +15,7 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Transient; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -47,19 +50,62 @@ public class Menu { columnDefinition = "binary(16)", foreignKey = @ForeignKey(name = "fk_menu_product_to_menu") ) - private List menuProducts; + private List menuProducts = new ArrayList<>(); @Transient private UUID menuGroupId; - public Menu(final Price price, final DisplayedName name, final MenuProduct menuProduct, final MenuGroup menuGroup) { - decideDisplay(menuProduct, price); + public static Menu createRequest(final Price price, final DisplayedName name, final List menuProducts, final UUID menuGroupId, final boolean displayed) { + return new Menu(price, name, menuProducts, menuGroupId, displayed); + } + public static Menu createRequest(final Price price) { + return new Menu(price); + } + + public Menu(final UUID id, + final Price price, + final DisplayedName name, + final boolean displayed, + final List menuProducts) { + decideDisplay(menuProducts, price); + this.id = id; + this.price = price; + this.name = name; + this.displayed = displayed; + this.menuProducts = menuProducts; + } + + public Menu(final Price price, final DisplayedName name, final List menuProducts, final MenuGroup menuGroup) { + hasMenuProducts(menuProducts); + decideDisplay(menuProducts, price); this.price = price; this.name = name; - this.menuProduct = menuProduct; + this.menuProducts = menuProducts; this.menuGroup = menuGroup; } + private Menu(final Price price) { + this.price = price; + } + + private static void hasMenuProducts(final List menuProducts) { + if (null == menuProducts || menuProducts.isEmpty()) { + throw new IllegalArgumentException(); + } + } + + private Menu(final Price price, + final DisplayedName name, + final List menuProducts, + final UUID menuGroupId, + final boolean displayed) { + this.price = price; + this.name = name; + this.menuProducts = menuProducts; + this.menuGroupId = menuGroupId; + this.displayed = displayed; + } + public Menu() { } @@ -75,10 +121,6 @@ public Price getPrice() { return price; } - public void setPrice(final Price price) { - this.price = price; - } - public DisplayedName getName() { return name; } @@ -99,12 +141,8 @@ public void setDisplayed(final boolean displayed) { this.displayed = displayed; } - public MenuProduct getMenuProduct() { - return menuProduct; - } - - public void setMenuProduct(final MenuProduct menuProduct) { - this.menuProduct = menuProduct; + public List getMenuProducts() { + return menuProducts; } public UUID getMenuGroupId() { @@ -116,7 +154,9 @@ public void setMenuGroupId(final UUID menuGroupId) { } public void changePrice(final Price price) { - decideDisplay(this.menuProduct, price); + if (!this.menuProducts.isEmpty()) { + decideDisplay(this.menuProducts, price); + } this.price = price; } @@ -133,17 +173,21 @@ public void displayOn() { this.displayed = true; } - private void decideDisplay(final MenuProduct menuProduct, final Price price) { - if (menuProduct.lessThan(price)) { - this.displayed = false; - return; + private void decideDisplay(final List menuProducts, final Price price) { + for (MenuProduct menuProduct : menuProducts) { + if (menuProduct.lessThan(price)) { + this.displayed = false; + return; + } + this.displayed = true; } - this.displayed = true; } private void validateDisplay() { - if (menuProduct.lessThan(price)) { - throw new IllegalArgumentException(CAN_NOT_DISPLAY_MESSAGE); + for (MenuProduct menuProduct : this.menuProducts) { + if (menuProduct.lessThan(price)) { + throw new IllegalArgumentException(CAN_NOT_DISPLAY_MESSAGE); + } } } } diff --git a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java index ea4c7221a..0d9fa0845 100644 --- a/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java +++ b/src/main/java/kitchenpos/menus/tobe/domain/MenuProduct.java @@ -1,5 +1,6 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.common.vo.Price; import kitchenpos.products.tobe.domain.Product; import javax.persistence.Column; @@ -12,7 +13,6 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Transient; -import java.math.BigDecimal; import java.util.UUID; @Table(name = "menu_product") @@ -47,11 +47,43 @@ public MenuProduct(final long quantity, final Product product) { this.product = product; } - protected MenuProduct() { + public MenuProduct() { + } + + public Long getSeq() { + return seq; + } + + public Product getProduct() { + return product; + } + + public long getQuantity() { + return quantity; + } + + public UUID getProductId() { + return productId; + } + + public void setSeq(final Long seq) { + this.seq = seq; + } + + public void setProduct(final Product product) { + this.product = product; + } + + public void setQuantity(final long quantity) { + this.quantity = quantity; + } + + public void setProductId(final UUID productId) { + this.productId = productId; } public Price getSumOfPrice() { - return new Price(product.getPrice().multiply(BigDecimal.valueOf(quantity))); + return product.getPrice().multiply(quantity); } public boolean lessThan(final Price price) { diff --git a/src/main/java/kitchenpos/menus/ui/MenuRestController.java b/src/main/java/kitchenpos/menus/ui/MenuRestController.java index 3e3a0e23a..4164bfbc1 100644 --- a/src/main/java/kitchenpos/menus/ui/MenuRestController.java +++ b/src/main/java/kitchenpos/menus/ui/MenuRestController.java @@ -1,9 +1,15 @@ package kitchenpos.menus.ui; import kitchenpos.menus.application.MenuService; -import kitchenpos.menus.domain.Menu; +import kitchenpos.menus.tobe.domain.Menu; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.net.URI; import java.util.List; diff --git a/src/test/java/kitchenpos/menus/application/InMemoryMenuRepository.java b/src/test/java/kitchenpos/menus/application/InMemoryMenuRepository.java index 971ded7e3..702bdd51f 100644 --- a/src/test/java/kitchenpos/menus/application/InMemoryMenuRepository.java +++ b/src/test/java/kitchenpos/menus/application/InMemoryMenuRepository.java @@ -1,9 +1,14 @@ package kitchenpos.menus.application; -import kitchenpos.menus.domain.Menu; import kitchenpos.menus.domain.MenuRepository; - -import java.util.*; +import kitchenpos.menus.tobe.domain.Menu; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; public class InMemoryMenuRepository implements MenuRepository { @@ -28,16 +33,16 @@ public List findAll() { @Override public List findAllByIdIn(final List ids) { return menus.values() - .stream() - .filter(menu -> ids.contains(menu.getId())) - .collect(Collectors.toList()); + .stream() + .filter(menu -> ids.contains(menu.getId())) + .collect(Collectors.toList()); } @Override public List findAllByProductId(final UUID productId) { return menus.values() - .stream() - .filter(menu -> menu.getMenuProducts().stream().anyMatch(menuProduct -> menuProduct.getProduct().getId().equals(productId))) - .collect(Collectors.toList()); + .stream() + .filter(menu -> menu.getMenuProducts().stream().anyMatch(menuProduct -> menuProduct.getProduct().getId().equals(productId))) + .collect(Collectors.toList()); } } diff --git a/src/test/java/kitchenpos/menus/application/MenuServiceTest.java b/src/test/java/kitchenpos/menus/application/MenuServiceTest.java index 9e527a3b8..2d819f59b 100644 --- a/src/test/java/kitchenpos/menus/application/MenuServiceTest.java +++ b/src/test/java/kitchenpos/menus/application/MenuServiceTest.java @@ -1,15 +1,19 @@ package kitchenpos.menus.application; -import kitchenpos.menus.domain.Menu; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; import kitchenpos.menus.domain.MenuGroupRepository; -import kitchenpos.menus.domain.MenuProduct; import kitchenpos.menus.domain.MenuRepository; +import kitchenpos.menus.tobe.domain.Menu; +import kitchenpos.menus.tobe.domain.MenuProduct; +import kitchenpos.common.vo.Price; import kitchenpos.products.application.FakePurgomalumClient; import kitchenpos.products.application.InMemoryProductRepository; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.Profanities; +import kitchenpos.common.infra.Profanities; import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -19,9 +23,17 @@ import org.junit.jupiter.params.provider.ValueSource; import java.math.BigDecimal; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.UUID; -import static kitchenpos.Fixtures.*; +import static kitchenpos.Fixtures.INVALID_ID; +import static kitchenpos.Fixtures.menu; +import static kitchenpos.Fixtures.menuGroup; +import static kitchenpos.Fixtures.menuProduct; +import static kitchenpos.Fixtures.product; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -50,17 +62,15 @@ void setUp() { @Test void create() { final Menu expected = createMenuRequest( - "후라이드+후라이드", 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) + "후라이드+후라이드", 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) ); final Menu actual = menuService.create(expected); assertThat(actual).isNotNull(); assertAll( - () -> assertThat(actual.getId()).isNotNull(), - () -> assertThat(actual.getName()).isEqualTo(expected.getName()), - () -> assertThat(actual.getPrice()).isEqualTo(expected.getPrice()), - () -> assertThat(actual.getMenuGroup().getId()).isEqualTo(expected.getMenuGroupId()), - () -> assertThat(actual.isDisplayed()).isEqualTo(expected.isDisplayed()), - () -> assertThat(actual.getMenuProducts()).hasSize(1) + () -> assertThat(actual.getName()).isEqualTo(expected.getName()), + () -> assertThat(actual.getPrice()).isEqualTo(expected.getPrice()), + () -> assertThat(actual.isDisplayed()).isEqualTo(expected.isDisplayed()), + () -> assertThat(actual.getMenuProducts()).hasSize(1) ); } @@ -70,14 +80,14 @@ void create() { void create(final List menuProducts) { final Menu expected = createMenuRequest("후라이드+후라이드", 19_000L, menuGroupId, true, menuProducts); assertThatThrownBy(() -> menuService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } private static List menuProducts() { return Arrays.asList( - null, - Arguments.of(Collections.emptyList()), - Arguments.of(Arrays.asList(createMenuProductRequest(INVALID_ID, 2L))) + null, + Arguments.of(Collections.emptyList()), + Arguments.of(Arrays.asList(createMenuProductRequest(INVALID_ID, 2L))) ); } @@ -85,32 +95,33 @@ private static List menuProducts() { @Test void createNegativeQuantity() { final Menu expected = createMenuRequest( - "후라이드+후라이드", 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), -1L) + "후라이드+후라이드", 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), -1L) ); assertThatThrownBy(() -> menuService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } + @Disabled // Price에서 검증 @DisplayName("메뉴의 가격이 올바르지 않으면 등록할 수 없다.") @ValueSource(strings = "-1000") @NullSource @ParameterizedTest void create(final BigDecimal price) { final Menu expected = createMenuRequest( - "후라이드+후라이드", price, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) + "후라이드+후라이드", price, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) ); assertThatThrownBy(() -> menuService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다.") @Test void createExpensiveMenu() { final Menu expected = createMenuRequest( - "후라이드+후라이드", 33_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) + "후라이드+후라이드", 33_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) ); assertThatThrownBy(() -> menuService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("메뉴는 특정 메뉴 그룹에 속해야 한다.") @@ -118,22 +129,23 @@ void createExpensiveMenu() { @ParameterizedTest void create(final UUID menuGroupId) { final Menu expected = createMenuRequest( - "후라이드+후라이드", 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) + "후라이드+후라이드", 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) ); assertThatThrownBy(() -> menuService.create(expected)) - .isInstanceOf(NoSuchElementException.class); + .isInstanceOf(NoSuchElementException.class); } + @Disabled // DisplayedName에서 검증 @DisplayName("메뉴의 이름이 올바르지 않으면 등록할 수 없다.") @ValueSource(strings = {"비속어", "욕설이 포함된 이름"}) @NullSource @ParameterizedTest void create(final String name) { final Menu expected = createMenuRequest( - name, 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) + name, 19_000L, menuGroupId, true, createMenuProductRequest(product.getId(), 2L) ); assertThatThrownBy(() -> menuService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("메뉴의 가격을 변경할 수 있다.") @@ -145,6 +157,8 @@ void changePrice() { assertThat(actual.getPrice()).isEqualTo(expected.getPrice()); } + // Price에서 검증 가능 + @Disabled @DisplayName("메뉴의 가격이 올바르지 않으면 변경할 수 없다.") @ValueSource(strings = "-1000") @NullSource @@ -153,7 +167,7 @@ void changePrice(final BigDecimal price) { final UUID menuId = menuRepository.save(menu(19_000L, menuProduct(product, 2L))).getId(); final Menu expected = changePriceRequest(price); assertThatThrownBy(() -> menuService.changePrice(menuId, expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("메뉴에 속한 상품 금액의 합은 메뉴의 가격보다 크거나 같아야 한다.") @@ -162,7 +176,7 @@ void changePriceToExpensive() { final UUID menuId = menuRepository.save(menu(19_000L, menuProduct(product, 2L))).getId(); final Menu expected = changePriceRequest(33_000L); assertThatThrownBy(() -> menuService.changePrice(menuId, expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("메뉴를 노출할 수 있다.") @@ -178,7 +192,7 @@ void display() { void displayExpensiveMenu() { final UUID menuId = menuRepository.save(menu(33_000L, false, menuProduct(product, 2L))).getId(); assertThatThrownBy(() -> menuService.display(menuId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("메뉴를 숨길 수 있다.") @@ -198,48 +212,49 @@ void findAll() { } private Menu createMenuRequest( - final String name, - final long price, - final UUID menuGroupId, - final boolean displayed, - final MenuProduct... menuProducts + final String name, + final long price, + final UUID menuGroupId, + final boolean displayed, + final MenuProduct... menuProducts ) { return createMenuRequest(name, BigDecimal.valueOf(price), menuGroupId, displayed, menuProducts); } private Menu createMenuRequest( - final String name, - final BigDecimal price, - final UUID menuGroupId, - final boolean displayed, - final MenuProduct... menuProducts + final String name, + final BigDecimal price, + final UUID menuGroupId, + final boolean displayed, + final MenuProduct... menuProducts ) { return createMenuRequest(name, price, menuGroupId, displayed, Arrays.asList(menuProducts)); } private Menu createMenuRequest( - final String name, - final long price, - final UUID menuGroupId, - final boolean displayed, - final List menuProducts + final String name, + final long price, + final UUID menuGroupId, + final boolean displayed, + final List menuProducts ) { return createMenuRequest(name, BigDecimal.valueOf(price), menuGroupId, displayed, menuProducts); } private Menu createMenuRequest( - final String name, - final BigDecimal price, - final UUID menuGroupId, - final boolean displayed, - final List menuProducts + final String name, + final BigDecimal price, + final UUID menuGroupId, + final boolean displayed, + final List menuProducts ) { - final Menu menu = new Menu(); - menu.setName(name); - menu.setPrice(price); - menu.setMenuGroupId(menuGroupId); - menu.setDisplayed(displayed); - menu.setMenuProducts(menuProducts); + final Menu menu = Menu.createRequest( + new Price(price), + new DisplayedName(name, new FakeProfanity()), + menuProducts, + menuGroupId, + displayed + ); return menu; } @@ -255,8 +270,7 @@ private Menu changePriceRequest(final long price) { } private Menu changePriceRequest(final BigDecimal price) { - final Menu menu = new Menu(); - menu.setPrice(price); + final Menu menu = Menu.createRequest(new Price(price)); return menu; } } diff --git a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java index c6ea27205..0ce355376 100644 --- a/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java +++ b/src/test/java/kitchenpos/menus/tobe/domain/MenuTest.java @@ -1,5 +1,8 @@ package kitchenpos.menus.tobe.domain; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.common.vo.Price; import kitchenpos.menus.domain.MenuGroup; import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.DisplayName; @@ -8,6 +11,7 @@ import org.junit.jupiter.params.provider.ValueSource; import java.math.BigDecimal; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -28,7 +32,7 @@ void construct() { final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); - final Menu menu = new Menu(price, name, menuProduct, new MenuGroup()); + final Menu menu = new Menu(price, name, List.of(menuProduct), new MenuGroup()); menu.changePrice(new Price(BigDecimal.ONE)); @@ -43,7 +47,7 @@ void greaterThanAndEqualsMenuProductPriceSum(final long productPrice) { final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(productPrice))); - assertThatCode(() -> new Menu(menuPrice, name, menuProduct, new MenuGroup())) + assertThatCode(() -> new Menu(menuPrice, name, List.of(menuProduct), new MenuGroup())) .doesNotThrowAnyException(); } @@ -55,7 +59,7 @@ void consistOfMenuGroup() { final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); final MenuGroup menuGroup = new MenuGroup(); - assertThatCode(() -> new Menu(menuPrice, name, menuProduct, menuGroup)) + assertThatCode(() -> new Menu(menuPrice, name, List.of(menuProduct), menuGroup)) .doesNotThrowAnyException(); } @@ -67,7 +71,7 @@ void displayed() { final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); final MenuGroup menuGroup = new MenuGroup(); - final Menu menu = new Menu(menuPrice, name, menuProduct, menuGroup); + final Menu menu = new Menu(menuPrice, name, List.of(menuProduct), menuGroup); menu.displayOff(); assertThat(menu.isDisplayed()).isFalse(); @@ -85,7 +89,7 @@ void displayOffWithInvalidPrice() { final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(4L))); final MenuGroup menuGroup = new MenuGroup(); - final Menu menu = new Menu(menuPrice, name, menuProduct, menuGroup); + final Menu menu = new Menu(menuPrice, name, List.of(menuProduct), menuGroup); assertThat(menu.isDisplayed()).isFalse(); assertThatThrownBy(() -> menu.displayOn()) From 867c3b60cb69f08b8426bb95df9d138496062253 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Thu, 20 Oct 2022 21:09:43 +0900 Subject: [PATCH 32/50] =?UTF-8?q?refactor(Product=20):=20package=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../products/application/ProductService.java | 22 +++++----- .../products/tobe/domain/Product.java | 19 +++++---- .../products/tobe/domain/ProductPrice.java | 42 ------------------- src/test/java/kitchenpos/Fixtures.java | 31 ++++++++------ .../application/ProductServiceTest.java | 21 +++++----- .../{ProductPriceTest.java => PriceTest.java} | 7 ++-- .../products/tobe/domain/ProductTest.java | 13 +++--- 7 files changed, 62 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java rename src/test/java/kitchenpos/products/tobe/domain/{ProductPriceTest.java => PriceTest.java} (72%) diff --git a/src/main/java/kitchenpos/products/application/ProductService.java b/src/main/java/kitchenpos/products/application/ProductService.java index caf137794..97e12c9d0 100644 --- a/src/main/java/kitchenpos/products/application/ProductService.java +++ b/src/main/java/kitchenpos/products/application/ProductService.java @@ -1,14 +1,14 @@ package kitchenpos.products.application; -import kitchenpos.menus.domain.Menu; -import kitchenpos.menus.domain.MenuProduct; +import kitchenpos.common.vo.DisplayedName; import kitchenpos.menus.domain.MenuRepository; +import kitchenpos.menus.tobe.domain.Menu; +import kitchenpos.menus.tobe.domain.MenuProduct; +import kitchenpos.common.vo.Price; import kitchenpos.products.application.dto.ProductRequest; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.Profanities; -import kitchenpos.products.tobe.domain.DisplayedName; +import kitchenpos.common.infra.Profanities; import kitchenpos.products.tobe.domain.Product; -import kitchenpos.products.tobe.domain.ProductPrice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,7 +36,7 @@ public ProductService( @Transactional public Product create(final ProductRequest request) { final Product product = new Product( - new ProductPrice(request.getPrice()), new DisplayedName(request.getName(), purgomalumClient)); + new Price(request.getPrice()), new DisplayedName(request.getName(), purgomalumClient)); return productRepository.save(product); } @@ -44,15 +44,13 @@ public Product create(final ProductRequest request) { public Product changePrice(final UUID productId, final ProductRequest request) { final Product product = productRepository.findById(productId) .orElseThrow(NoSuchElementException::new); - product.changePrice(new ProductPrice(request.getPrice())); + product.changePrice(new Price(request.getPrice())); final List menus = menuRepository.findAllByProductId(productId); for (final Menu menu : menus) { - BigDecimal sum = BigDecimal.ZERO; + Price sum = new Price(BigDecimal.ZERO); for (final MenuProduct menuProduct : menu.getMenuProducts()) { - sum = sum.add( - menuProduct.getProduct() - .getPrice() - .multiply(BigDecimal.valueOf(menuProduct.getQuantity())) + sum.add( + menuProduct.getSumOfPrice() ); } if (menu.getPrice().compareTo(sum) > 0) { diff --git a/src/main/java/kitchenpos/products/tobe/domain/Product.java b/src/main/java/kitchenpos/products/tobe/domain/Product.java index bf094331f..797e411cc 100644 --- a/src/main/java/kitchenpos/products/tobe/domain/Product.java +++ b/src/main/java/kitchenpos/products/tobe/domain/Product.java @@ -1,5 +1,8 @@ package kitchenpos.products.tobe.domain; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.common.vo.Price; + import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; @@ -16,28 +19,28 @@ public class Product { private UUID id; @Embedded - private ProductPrice price; + private Price price; @Embedded private DisplayedName name; - public Product(final UUID id, final ProductPrice price, final DisplayedName name) { + public Product(final UUID id, final Price price, final DisplayedName name) { this.id = id; this.price = price; this.name = name; } - public Product(final ProductPrice price, final DisplayedName name) { + public Product(final Price price, final DisplayedName name) { this.price = price; this.name = name; } - public Product(final ProductPrice price) { + public Product(final Price price) { this.price = price; } public Product(BigDecimal price) { - this(new ProductPrice(price)); + this(new Price(price)); } protected Product() { @@ -47,7 +50,7 @@ public UUID getId() { return id; } - public ProductPrice getPrice() { + public Price getPrice() { return price; } @@ -59,7 +62,7 @@ public void setId(final UUID id) { this.id = id; } - public void setPrice(final ProductPrice price) { + public void setPrice(final Price price) { this.price = price; } @@ -67,7 +70,7 @@ public void setName(final DisplayedName name) { this.name = name; } - public void changePrice(final ProductPrice price) { + public void changePrice(final Price price) { this.price = price; } } diff --git a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java b/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java deleted file mode 100644 index 663b2de21..000000000 --- a/src/main/java/kitchenpos/products/tobe/domain/ProductPrice.java +++ /dev/null @@ -1,42 +0,0 @@ -package kitchenpos.products.tobe.domain; - -import javax.persistence.Column; -import javax.persistence.Embeddable; -import java.math.BigDecimal; -import java.util.Objects; - -@Embeddable -public class ProductPrice { - private static final String INVALID_PRICE_MESSAGE = "상품 가격은 0보다 크거다 같아야 합니다."; - - @Column(name = "price", nullable = false) - private final BigDecimal price; - - public ProductPrice(final BigDecimal price) { - if (price.compareTo(BigDecimal.ZERO) < 0) { - throw new IllegalArgumentException(INVALID_PRICE_MESSAGE); - } - this.price = price; - } - - public ProductPrice() { - this.price = null; - } - - public BigDecimal multiply(BigDecimal price) { - return this.price.multiply(price); - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (null == o || getClass() != o.getClass()) return false; - final ProductPrice that = (ProductPrice) o; - return price == null ? that.price == null : price.compareTo(that.price) == 0; - } - - @Override - public int hashCode() { - return Objects.hash(price); - } -} diff --git a/src/test/java/kitchenpos/Fixtures.java b/src/test/java/kitchenpos/Fixtures.java index d4a5657ce..fc05e5fc4 100644 --- a/src/test/java/kitchenpos/Fixtures.java +++ b/src/test/java/kitchenpos/Fixtures.java @@ -1,13 +1,18 @@ package kitchenpos; -import kitchenpos.eatinorders.domain.*; -import kitchenpos.menus.domain.Menu; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.eatinorders.domain.Order; +import kitchenpos.eatinorders.domain.OrderLineItem; +import kitchenpos.eatinorders.domain.OrderStatus; +import kitchenpos.eatinorders.domain.OrderTable; +import kitchenpos.eatinorders.domain.OrderType; import kitchenpos.menus.domain.MenuGroup; -import kitchenpos.menus.domain.MenuProduct; +import kitchenpos.menus.tobe.domain.Menu; +import kitchenpos.menus.tobe.domain.MenuProduct; +import kitchenpos.common.vo.Price; import kitchenpos.products.application.FakePurgomalumClient; -import kitchenpos.products.tobe.domain.DisplayedName; import kitchenpos.products.tobe.domain.Product; -import kitchenpos.products.tobe.domain.ProductPrice; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -27,13 +32,13 @@ public static Menu menu(final long price, final MenuProduct... menuProducts) { } public static Menu menu(final long price, final boolean displayed, final MenuProduct... menuProducts) { - final Menu menu = new Menu(); - menu.setId(UUID.randomUUID()); - menu.setName("후라이드+후라이드"); - menu.setPrice(BigDecimal.valueOf(price)); - menu.setMenuGroup(menuGroup()); - menu.setDisplayed(displayed); - menu.setMenuProducts(Arrays.asList(menuProducts)); + final Menu menu = new Menu( + UUID.randomUUID(), + new Price(BigDecimal.valueOf(price)), + new DisplayedName("후라이드+후라이드", new FakeProfanity()), + displayed, + Arrays.asList(menuProducts) + ); return menu; } @@ -123,7 +128,7 @@ public static Product product() { public static Product product(final String name, final long price) { final Product product = new Product( UUID.randomUUID(), - new ProductPrice(BigDecimal.valueOf(price)), + new Price(BigDecimal.valueOf(price)), new DisplayedName(name, new FakePurgomalumClient()) ); return product; diff --git a/src/test/java/kitchenpos/products/application/ProductServiceTest.java b/src/test/java/kitchenpos/products/application/ProductServiceTest.java index bc8a6c8da..89102ad9b 100644 --- a/src/test/java/kitchenpos/products/application/ProductServiceTest.java +++ b/src/test/java/kitchenpos/products/application/ProductServiceTest.java @@ -1,11 +1,11 @@ package kitchenpos.products.application; import kitchenpos.menus.application.InMemoryMenuRepository; -import kitchenpos.menus.domain.Menu; import kitchenpos.menus.domain.MenuRepository; +import kitchenpos.menus.tobe.domain.Menu; import kitchenpos.products.application.dto.ProductRequest; import kitchenpos.products.domain.ProductRepository; -import kitchenpos.products.infra.Profanities; +import kitchenpos.common.infra.Profanities; import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -18,7 +18,9 @@ import java.util.List; import java.util.UUID; -import static kitchenpos.Fixtures.*; +import static kitchenpos.Fixtures.menu; +import static kitchenpos.Fixtures.menuProduct; +import static kitchenpos.Fixtures.product; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -44,9 +46,8 @@ void create() { final Product actual = productService.create(expected); assertThat(actual).isNotNull(); assertAll( - () -> assertThat(actual.getId()).isNotNull(), - () -> assertThat(actual.getName()).isEqualTo(expected.getName()), - () -> assertThat(actual.getPrice()).isEqualTo(expected.getPrice()) + () -> assertThat(actual.getName().getName()).isEqualTo(expected.getName()), + () -> assertThat(actual.getPrice().getPrice()).isEqualTo(expected.getPrice()) ); } @@ -57,7 +58,7 @@ void create() { void create(final BigDecimal price) { final ProductRequest expected = createProductRequest("후라이드", price); assertThatThrownBy(() -> productService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("상품의 이름이 올바르지 않으면 등록할 수 없다.") @@ -67,7 +68,7 @@ void create(final BigDecimal price) { void create(final String name) { final ProductRequest expected = createProductRequest(name, 16_000L); assertThatThrownBy(() -> productService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("상품의 가격을 변경할 수 있다.") @@ -76,7 +77,7 @@ void changePrice() { final UUID productId = productRepository.save(product("후라이드", 16_000L)).getId(); final ProductRequest expected = changePriceRequest(15_000L); final Product actual = productService.changePrice(productId, expected); - assertThat(actual.getPrice()).isEqualTo(expected.getPrice()); + assertThat(actual.getPrice().getPrice()).isEqualTo(expected.getPrice()); } @DisplayName("상품의 가격이 올바르지 않으면 변경할 수 없다.") @@ -87,7 +88,7 @@ void changePrice(final BigDecimal price) { final UUID productId = productRepository.save(product("후라이드", 16_000L)).getId(); final ProductRequest expected = changePriceRequest(price); assertThatThrownBy(() -> productService.changePrice(productId, expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("상품의 가격이 변경될 때 메뉴의 가격이 메뉴에 속한 상품 금액의 합보다 크면 메뉴가 숨겨진다.") diff --git a/src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java b/src/test/java/kitchenpos/products/tobe/domain/PriceTest.java similarity index 72% rename from src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java rename to src/test/java/kitchenpos/products/tobe/domain/PriceTest.java index debc04671..30d087392 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/ProductPriceTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/PriceTest.java @@ -1,5 +1,6 @@ package kitchenpos.products.tobe.domain; +import kitchenpos.common.vo.Price; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -7,14 +8,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; -class ProductPriceTest { +class PriceTest { @DisplayName("상품의 가격은 0보다 크거나 같아야 한다.") @Test void registerWithLessThanZero() { - final String INVALID_PRICE_MESSAGE = "상품 가격은 0보다 크거다 같아야 합니다."; + final String INVALID_PRICE_MESSAGE = "가격은 0보다 크거다 같아야 합니다."; final BigDecimal price = BigDecimal.valueOf(-1L); - assertThatThrownBy(() -> new ProductPrice(price)) + assertThatThrownBy(() -> new Price(price)) .isInstanceOf(IllegalArgumentException.class) .hasMessage(INVALID_PRICE_MESSAGE); } diff --git a/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java b/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java index cfc2da10d..ecddba440 100644 --- a/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java +++ b/src/test/java/kitchenpos/products/tobe/domain/ProductTest.java @@ -1,5 +1,8 @@ package kitchenpos.products.tobe.domain; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.common.vo.Price; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,8 +14,8 @@ class ProductTest { @DisplayName("상품을 등록할 수 있다.") @Test void register() { - final ProductPrice price = new ProductPrice(BigDecimal.TEN); - final DisplayedName name = new DisplayedName("chicken", new FakeProfanities()); + final Price price = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("chicken", new FakeProfanity()); assertThatCode(() -> new Product(price, name)) .doesNotThrowAnyException(); @@ -21,10 +24,10 @@ void register() { @DisplayName("가격을 변경할 수 있다.") @Test void changePrice() { - final ProductPrice price = new ProductPrice(BigDecimal.TEN); - final DisplayedName name = new DisplayedName("chicken", new FakeProfanities()); + final Price price = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("chicken", new FakeProfanity()); Product product = new Product(price, name); - product.changePrice(new ProductPrice(BigDecimal.ONE)); + product.changePrice(new Price(BigDecimal.ONE)); } } From 7d4eafb8fb9524a9f34d866daf2a78b38f25a4b4 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 07:31:20 +0900 Subject: [PATCH 33/50] =?UTF-8?q?docs(OrderTest):=20=EC=9A=94=EA=B5=AC?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 11 ++++ .../eatinorders/tobe/domain/OrderTest.java | 53 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java create mode 100644 src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java new file mode 100644 index 000000000..892335a92 --- /dev/null +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -0,0 +1,11 @@ +package kitchenpos.eatinorders.tobe.domain; + +import kitchenpos.eatinorders.domain.OrderType; + +public class Order { + private OrderType orderType; + + public Order(final OrderType orderType) { + this.orderType = orderType; + } +} diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java new file mode 100644 index 000000000..cd587cce1 --- /dev/null +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -0,0 +1,53 @@ +package kitchenpos.eatinorders.tobe.domain; + +import kitchenpos.eatinorders.domain.OrderType; +import org.junit.jupiter.api.DisplayName; + +import static org.assertj.core.api.Assertions.assertThatCode; + +/* +공통 +- [x] 주문 유형이 올바르지 않으면 등록할 수 없다. +- 메뉴가 없으면 등록할 수 없다. +- 숨겨진 메뉴는 주문할 수 없다. +- 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. +- 주문을 접수한다. +- 접수 대기 중인 주문만 접수할 수 있다. +- 주문을 완료한다. +- 주문을 서빙한다. +- 접수된 주문만 서빙할 수 있다. +- 주문 목록을 조회할 수 있다. + +매장 +- 매장 주문은 주문 항목의 수량이 0 미만일 수 있다. +- 매장 주문을 제외한 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. +- 매장 주문의 경우 서빙된 주문만 완료할 수 있다. +- 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. +- 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. +- 1개 이상의 등록된 메뉴로 매장 주문을 등록할 수 있다. +- 빈 테이블에는 매장 주문을 등록할 수 없다. + +포장 +- 포장 주문의 경우 서빙된 주문만 완료할 수 있다. +- 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. + +배달 +- 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. +- 배달 주문을 접수되면 배달 대행사를 호출한다. +- 주문을 배달한다. +- 배달 주문만 배달할 수 있다. +- 서빙된 주문만 배달할 수 있다. +- 주문을 배달 완료한다. +- 배달 중인 주문만 배달 완료할 수 있다. +- 배달 주문의 경우 배달 완료된 주문만 완료할 수 있다. +- 배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다. + - 배달 주소는 비워 둘 수 없다. + */ + +class OrderTest { + @DisplayName("주문 유형이 올바르지 않으면 등록할 수 없다.") + void registerWithValidOrderType() { + assertThatCode(() -> new Order(OrderType.EAT_IN)) + .doesNotThrowAnyException(); + } +} From 3a0129a6f45ce538730f8374248c13ea01a16344 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 07:43:32 +0900 Subject: [PATCH 34/50] =?UTF-8?q?feat(Order):=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=EA=B0=80=20=EC=97=86=EC=9C=BC=EB=A9=B4=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=97=86=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/eatinorders/tobe/domain/Order.java | 7 ++++++- .../eatinorders/tobe/domain/OrderLineItem.java | 4 ++++ .../eatinorders/tobe/domain/OrderTest.java | 12 ++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index 892335a92..2fd435d4c 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -2,10 +2,15 @@ import kitchenpos.eatinorders.domain.OrderType; +import java.util.List; + public class Order { private OrderType orderType; - public Order(final OrderType orderType) { + private List orderLineItems; + + public Order(final OrderType orderType, final List orderLineItems) { this.orderType = orderType; + this.orderLineItems = orderLineItems; } } diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java new file mode 100644 index 000000000..f7ffb3f62 --- /dev/null +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java @@ -0,0 +1,4 @@ +package kitchenpos.eatinorders.tobe.domain; + +public class OrderLineItem { +} diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index cd587cce1..51ba773f1 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -3,12 +3,14 @@ import kitchenpos.eatinorders.domain.OrderType; import org.junit.jupiter.api.DisplayName; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThatCode; /* 공통 - [x] 주문 유형이 올바르지 않으면 등록할 수 없다. -- 메뉴가 없으면 등록할 수 없다. +- [x] 메뉴가 없으면 등록할 수 없다. - 숨겨진 메뉴는 주문할 수 없다. - 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. - 주문을 접수한다. @@ -47,7 +49,13 @@ class OrderTest { @DisplayName("주문 유형이 올바르지 않으면 등록할 수 없다.") void registerWithValidOrderType() { - assertThatCode(() -> new Order(OrderType.EAT_IN)) + assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem()))) + .doesNotThrowAnyException(); + } + + @DisplayName("메뉴가 없으면 등록할 수 없다.") + void registerWithMenu() { + assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem()))) .doesNotThrowAnyException(); } } From 8cdc1e5d9f70f0eb2f322817bd1a1883234e99f5 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 07:53:40 +0900 Subject: [PATCH 35/50] =?UTF-8?q?feat(Order):=20=EC=88=A8=EA=B2=A8?= =?UTF-8?q?=EC=A7=84=20=EB=A9=94=EB=89=B4=EB=8A=94=20=EC=A3=BC=EB=AC=B8?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=97=86=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 4 +-- .../tobe/domain/OrderLineItem.java | 6 ++++ .../eatinorders/tobe/domain/OrderTest.java | 32 +++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index 2fd435d4c..40569d86e 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -5,9 +5,9 @@ import java.util.List; public class Order { - private OrderType orderType; + private final OrderType orderType; - private List orderLineItems; + private final List orderLineItems; public Order(final OrderType orderType, final List orderLineItems) { this.orderType = orderType; diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java index f7ffb3f62..929ec0209 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java @@ -1,4 +1,10 @@ package kitchenpos.eatinorders.tobe.domain; +import kitchenpos.menus.tobe.domain.Menu; + public class OrderLineItem { + private final Menu menu; + public OrderLineItem(final Menu menu) { + this.menu = menu; + } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 51ba773f1..57172e0ba 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -1,8 +1,17 @@ package kitchenpos.eatinorders.tobe.domain; +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.common.vo.Price; import kitchenpos.eatinorders.domain.OrderType; +import kitchenpos.menus.domain.MenuGroup; +import kitchenpos.menus.tobe.domain.Menu; +import kitchenpos.menus.tobe.domain.MenuProduct; +import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import java.math.BigDecimal; import java.util.List; import static org.assertj.core.api.Assertions.assertThatCode; @@ -11,7 +20,7 @@ 공통 - [x] 주문 유형이 올바르지 않으면 등록할 수 없다. - [x] 메뉴가 없으면 등록할 수 없다. -- 숨겨진 메뉴는 주문할 수 없다. +- [x] 숨겨진 메뉴는 주문할 수 없다. - 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. - 주문을 접수한다. - 접수 대기 중인 주문만 접수할 수 있다. @@ -48,14 +57,31 @@ class OrderTest { @DisplayName("주문 유형이 올바르지 않으면 등록할 수 없다.") + @Test void registerWithValidOrderType() { - assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem()))) + assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem(createMenu())))) .doesNotThrowAnyException(); } @DisplayName("메뉴가 없으면 등록할 수 없다.") + @Test void registerWithMenu() { - assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem()))) + assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem(createMenu())))) .doesNotThrowAnyException(); } + + @DisplayName("숨겨진 메뉴는 주문할 수 없다.") + @Test + void hideMenu() { + final Menu menu = createMenu(); + assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem(menu)))) + .doesNotThrowAnyException(); + } + + private Menu createMenu() { + final Price price = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); + return new Menu(price, name, List.of(menuProduct), new MenuGroup()); + } } From 953894018525eedb3fde0197a3539dd390054249 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 08:09:10 +0900 Subject: [PATCH 36/50] =?UTF-8?q?feat(Order):=20=EC=A0=91=EC=88=98=20?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=20=EC=A4=91=EC=9D=B8=20=EC=A3=BC=EB=AC=B8?= =?UTF-8?q?=EB=A7=8C=20=EC=A0=91=EC=88=98=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 18 +++++++++- .../eatinorders/tobe/domain/OrderTest.java | 33 +++++++++++++++---- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index 40569d86e..bad45f705 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -1,16 +1,32 @@ package kitchenpos.eatinorders.tobe.domain; +import kitchenpos.eatinorders.domain.OrderStatus; import kitchenpos.eatinorders.domain.OrderType; import java.util.List; public class Order { + private static final String INVALID_ORDER_STATUS_MESSAGE = "대기 상태에만 수락상태로 변경할 수 있습니다."; private final OrderType orderType; private final List orderLineItems; - public Order(final OrderType orderType, final List orderLineItems) { + private OrderStatus orderStatus; + + public Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus) { this.orderType = orderType; this.orderLineItems = orderLineItems; + this.orderStatus = orderStatus; + } + + public OrderStatus getOrderStatus() { + return orderStatus; + } + + public void accept() { + if (orderStatus != OrderStatus.WAITING) { + throw new IllegalArgumentException(INVALID_ORDER_STATUS_MESSAGE); + } + orderStatus = OrderStatus.ACCEPTED; } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 57172e0ba..bcdccdf97 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -3,6 +3,7 @@ import kitchenpos.common.FakeProfanity; import kitchenpos.common.vo.DisplayedName; import kitchenpos.common.vo.Price; +import kitchenpos.eatinorders.domain.OrderStatus; import kitchenpos.eatinorders.domain.OrderType; import kitchenpos.menus.domain.MenuGroup; import kitchenpos.menus.tobe.domain.Menu; @@ -14,6 +15,7 @@ import java.math.BigDecimal; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; /* @@ -21,13 +23,13 @@ - [x] 주문 유형이 올바르지 않으면 등록할 수 없다. - [x] 메뉴가 없으면 등록할 수 없다. - [x] 숨겨진 메뉴는 주문할 수 없다. -- 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. - 주문을 접수한다. -- 접수 대기 중인 주문만 접수할 수 있다. + - [x] 접수 대기 중인 주문만 접수할 수 있다. - 주문을 완료한다. - 주문을 서빙한다. - 접수된 주문만 서빙할 수 있다. - 주문 목록을 조회할 수 있다. +- [] 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. 매장 - 매장 주문은 주문 항목의 수량이 0 미만일 수 있다. @@ -59,25 +61,44 @@ class OrderTest { @DisplayName("주문 유형이 올바르지 않으면 등록할 수 없다.") @Test void registerWithValidOrderType() { - assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem(createMenu())))) + assertThatCode(() -> createOrder()) .doesNotThrowAnyException(); } + @DisplayName("메뉴가 없으면 등록할 수 없다.") @Test void registerWithMenu() { - assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem(createMenu())))) + assertThatCode(() -> createOrder()) .doesNotThrowAnyException(); } @DisplayName("숨겨진 메뉴는 주문할 수 없다.") @Test void hideMenu() { - final Menu menu = createMenu(); - assertThatCode(() -> new Order(OrderType.EAT_IN, List.of(new OrderLineItem(menu)))) + assertThatCode(() -> createOrder()) .doesNotThrowAnyException(); } + @DisplayName("접수 대기 중인 주문만 접수할 수 있다.") + @Test + void price() { + final Order order = createOrder(); + + order.accept(); + + assertThat(order.getOrderStatus()).isEqualTo(OrderStatus.ACCEPTED); + } + + private Order createOrder() { + final OrderType orderType = OrderType.EAT_IN; + final Menu menu = createMenu(); + final List orderLineItems = List.of(new OrderLineItem(menu)); + final OrderStatus orderStatus = OrderStatus.WAITING; + + return new Order(orderType, orderLineItems, orderStatus); + } + private Menu createMenu() { final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); From f0a61a6f5b5de8e5e51764485ff51935b0adfe7e Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 08:31:39 +0900 Subject: [PATCH 37/50] =?UTF-8?q?feat(Order):=20=EC=A0=91=EC=88=98?= =?UTF-8?q?=EB=90=9C=20=EC=A3=BC=EB=AC=B8=EB=A7=8C=20=EC=84=9C=EB=B9=99?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 12 ++++++++++-- .../eatinorders/tobe/domain/OrderTest.java | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index bad45f705..7a52bd14a 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -6,7 +6,8 @@ import java.util.List; public class Order { - private static final String INVALID_ORDER_STATUS_MESSAGE = "대기 상태에만 수락상태로 변경할 수 있습니다."; + private static final String NOT_WAITING_MESSAGE = "대기 상태에만 수락상태로 변경할 수 있습니다."; + private static final String NOT_ACCEPT_MESSAGE = "수락 상태에만 서빙상태로 변경할 수 있습니다."; private final OrderType orderType; private final List orderLineItems; @@ -25,8 +26,15 @@ public OrderStatus getOrderStatus() { public void accept() { if (orderStatus != OrderStatus.WAITING) { - throw new IllegalArgumentException(INVALID_ORDER_STATUS_MESSAGE); + throw new IllegalArgumentException(NOT_WAITING_MESSAGE); } orderStatus = OrderStatus.ACCEPTED; } + + public void serve() { + if (orderStatus != OrderStatus.ACCEPTED) { + throw new IllegalArgumentException(NOT_ACCEPT_MESSAGE); + } + orderStatus = OrderStatus.SERVED; + } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index bcdccdf97..2538a7332 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -25,9 +25,10 @@ - [x] 숨겨진 메뉴는 주문할 수 없다. - 주문을 접수한다. - [x] 접수 대기 중인 주문만 접수할 수 있다. -- 주문을 완료한다. - 주문을 서빙한다. -- 접수된 주문만 서빙할 수 있다. +- [x] 접수된 주문만 서빙할 수 있다. +- 주문을 완료한다. + - 주문 목록을 조회할 수 있다. - [] 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. @@ -82,7 +83,7 @@ void hideMenu() { @DisplayName("접수 대기 중인 주문만 접수할 수 있다.") @Test - void price() { + void accept() { final Order order = createOrder(); order.accept(); @@ -90,6 +91,17 @@ void price() { assertThat(order.getOrderStatus()).isEqualTo(OrderStatus.ACCEPTED); } + @DisplayName("접수된 주문만 서빙할 수 있다.") + @Test + void serve() { + final Order order = createOrder(); + order.accept(); + + order.serve(); + + assertThat(order.getOrderStatus()).isEqualTo(OrderStatus.SERVED); + } + private Order createOrder() { final OrderType orderType = OrderType.EAT_IN; final Menu menu = createMenu(); From 5f5500146cf70df7c2156d444d237ed3d5f599d9 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 08:47:23 +0900 Subject: [PATCH 38/50] =?UTF-8?q?feat(Order):=20=EB=A7=A4=EC=9E=A5=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=80=20=EC=A3=BC=EB=AC=B8=20=ED=95=AD?= =?UTF-8?q?=EB=AA=A9=EC=9D=98=20=EC=88=98=EB=9F=89=EC=9D=B4=200=20?= =?UTF-8?q?=EB=AF=B8=EB=A7=8C=EC=9D=BC=20=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 4 ++ .../tobe/domain/OrderLineItem.java | 9 +++- .../eatinorders/tobe/domain/OrderTest.java | 46 +++++-------------- .../tobe/domain/fixture/OrderFixture.java | 35 ++++++++++++++ 4 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index 7a52bd14a..a94c654f6 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -8,6 +8,7 @@ public class Order { private static final String NOT_WAITING_MESSAGE = "대기 상태에만 수락상태로 변경할 수 있습니다."; private static final String NOT_ACCEPT_MESSAGE = "수락 상태에만 서빙상태로 변경할 수 있습니다."; + private static final String CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN = "매장 주문이 아니라면 주문 수량은 0보다 크거나 같아야 한다."; private final OrderType orderType; private final List orderLineItems; @@ -15,6 +16,9 @@ public class Order { private OrderStatus orderStatus; public Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus) { + if (orderType != OrderType.EAT_IN && orderLineItems.stream().anyMatch(o -> o.getQuantity() < 0)) { + throw new IllegalArgumentException(CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN); + } this.orderType = orderType; this.orderLineItems = orderLineItems; this.orderStatus = orderStatus; diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java index 929ec0209..b95c80d19 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java @@ -4,7 +4,14 @@ public class OrderLineItem { private final Menu menu; - public OrderLineItem(final Menu menu) { + private final long quantity; + + public OrderLineItem(final Menu menu, final long quantity) { this.menu = menu; + this.quantity = quantity; + } + + public long getQuantity() { + return quantity; } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 2538a7332..e46706c57 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -1,20 +1,10 @@ package kitchenpos.eatinorders.tobe.domain; -import kitchenpos.common.FakeProfanity; -import kitchenpos.common.vo.DisplayedName; -import kitchenpos.common.vo.Price; import kitchenpos.eatinorders.domain.OrderStatus; -import kitchenpos.eatinorders.domain.OrderType; -import kitchenpos.menus.domain.MenuGroup; -import kitchenpos.menus.tobe.domain.Menu; -import kitchenpos.menus.tobe.domain.MenuProduct; -import kitchenpos.products.tobe.domain.Product; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.math.BigDecimal; -import java.util.List; - +import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createEatInOrder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -27,13 +17,10 @@ - [x] 접수 대기 중인 주문만 접수할 수 있다. - 주문을 서빙한다. - [x] 접수된 주문만 서빙할 수 있다. -- 주문을 완료한다. - -- 주문 목록을 조회할 수 있다. - [] 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. 매장 -- 매장 주문은 주문 항목의 수량이 0 미만일 수 있다. +- [x] 매장 주문은 주문 항목의 수량이 0 미만일 수 있다. - 매장 주문을 제외한 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. - 매장 주문의 경우 서빙된 주문만 완료할 수 있다. - 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. @@ -62,7 +49,7 @@ class OrderTest { @DisplayName("주문 유형이 올바르지 않으면 등록할 수 없다.") @Test void registerWithValidOrderType() { - assertThatCode(() -> createOrder()) + assertThatCode(() -> createEatInOrder()) .doesNotThrowAnyException(); } @@ -70,21 +57,21 @@ void registerWithValidOrderType() { @DisplayName("메뉴가 없으면 등록할 수 없다.") @Test void registerWithMenu() { - assertThatCode(() -> createOrder()) + assertThatCode(() -> createEatInOrder()) .doesNotThrowAnyException(); } @DisplayName("숨겨진 메뉴는 주문할 수 없다.") @Test void hideMenu() { - assertThatCode(() -> createOrder()) + assertThatCode(() -> createEatInOrder()) .doesNotThrowAnyException(); } @DisplayName("접수 대기 중인 주문만 접수할 수 있다.") @Test void accept() { - final Order order = createOrder(); + final Order order = createEatInOrder(); order.accept(); @@ -94,7 +81,7 @@ void accept() { @DisplayName("접수된 주문만 서빙할 수 있다.") @Test void serve() { - final Order order = createOrder(); + final Order order = createEatInOrder(); order.accept(); order.serve(); @@ -102,19 +89,10 @@ void serve() { assertThat(order.getOrderStatus()).isEqualTo(OrderStatus.SERVED); } - private Order createOrder() { - final OrderType orderType = OrderType.EAT_IN; - final Menu menu = createMenu(); - final List orderLineItems = List.of(new OrderLineItem(menu)); - final OrderStatus orderStatus = OrderStatus.WAITING; - - return new Order(orderType, orderLineItems, orderStatus); - } - - private Menu createMenu() { - final Price price = new Price(BigDecimal.TEN); - final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); - final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); - return new Menu(price, name, List.of(menuProduct), new MenuGroup()); + @DisplayName("매장 주문은 주문 항목의 수량이 0 미만일 수 있다.") + @Test + void quantity() { + assertThatCode(() -> createEatInOrder()) + .doesNotThrowAnyException(); } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java new file mode 100644 index 000000000..86b554466 --- /dev/null +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java @@ -0,0 +1,35 @@ +package kitchenpos.eatinorders.tobe.domain.fixture; + +import kitchenpos.common.FakeProfanity; +import kitchenpos.common.vo.DisplayedName; +import kitchenpos.common.vo.Price; +import kitchenpos.eatinorders.domain.OrderStatus; +import kitchenpos.eatinorders.domain.OrderType; +import kitchenpos.eatinorders.tobe.domain.Order; +import kitchenpos.eatinorders.tobe.domain.OrderLineItem; +import kitchenpos.menus.domain.MenuGroup; +import kitchenpos.menus.tobe.domain.Menu; +import kitchenpos.menus.tobe.domain.MenuProduct; +import kitchenpos.products.tobe.domain.Product; + +import java.math.BigDecimal; +import java.util.List; + +public class OrderFixture { + public static Order createEatInOrder() { + final OrderType orderType = OrderType.EAT_IN; + final Menu menu = createMenu(); + final List orderLineItems = List.of(new OrderLineItem(menu, -1L)); + final OrderStatus orderStatus = OrderStatus.WAITING; + + return new Order(orderType, orderLineItems, orderStatus); + } + + private static Menu createMenu() { + final Price price = new Price(BigDecimal.TEN); + final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); + final MenuProduct menuProduct = new MenuProduct(2L, new Product(BigDecimal.valueOf(6L))); + return new Menu(price, name, List.of(menuProduct), new MenuGroup()); + } + +} From 1f83984875010a71831532123746190a3d623c39 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 18:38:26 +0900 Subject: [PATCH 39/50] =?UTF-8?q?docs(OrderTest):=20=EC=9A=94=EA=B5=AC?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/eatinorders/tobe/domain/OrderTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index e46706c57..c0e4f80c6 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -21,17 +21,16 @@ 매장 - [x] 매장 주문은 주문 항목의 수량이 0 미만일 수 있다. -- 매장 주문을 제외한 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. -- 매장 주문의 경우 서빙된 주문만 완료할 수 있다. +- [x] 매장 주문의 경우 서빙된 주문만 완료할 수 있다. +- [x] 1개 이상의 등록된 메뉴로 매장 주문을 등록할 수 있다. - 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. - 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. -- 1개 이상의 등록된 메뉴로 매장 주문을 등록할 수 있다. - 빈 테이블에는 매장 주문을 등록할 수 없다. 포장 - 포장 주문의 경우 서빙된 주문만 완료할 수 있다. - 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. - +- 포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. 배달 - 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. - 배달 주문을 접수되면 배달 대행사를 호출한다. @@ -43,6 +42,7 @@ - 배달 주문의 경우 배달 완료된 주문만 완료할 수 있다. - 배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다. - 배달 주소는 비워 둘 수 없다. +- 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. */ class OrderTest { From 4eacdb9704b328718bafe9728d3dc87c48ddc6a7 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 19:19:28 +0900 Subject: [PATCH 40/50] =?UTF-8?q?feat(OrderTable):=20=EC=A3=BC=EB=AC=B8=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=EC=9D=98=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EB=A7=A4=EC=9E=A5=20=EC=A3=BC=EB=AC=B8=EC=9D=B4=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EB=90=98=EB=A9=B4=20=EB=B9=88=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EB=A1=9C=20=EC=84=A4=EC=A0=95=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 24 +++++++++++++++---- .../eatinorders/tobe/domain/OrderTable.java | 20 ++++++++++++++++ .../eatinorders/tobe/domain/OrderTest.java | 14 ++++++++++- .../tobe/domain/fixture/OrderFixture.java | 4 +++- 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index a94c654f6..ad5d25bad 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -6,28 +6,34 @@ import java.util.List; public class Order { - private static final String NOT_WAITING_MESSAGE = "대기 상태에만 수락상태로 변경할 수 있습니다."; - private static final String NOT_ACCEPT_MESSAGE = "수락 상태에만 서빙상태로 변경할 수 있습니다."; + private static final String NOT_WAITING_MESSAGE = "대기 상태에만 수락 상태로 변경할 수 있습니다."; + private static final String NOT_ACCEPT_MESSAGE = "수락 상태에만 서빙 완료 상태로 변경할 수 있습니다."; + private static final String NOT_SERVED_MESSAGE = "서빙 완료 상태에서만 완료 상태로 변경할 수 있습니다."; private static final String CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN = "매장 주문이 아니라면 주문 수량은 0보다 크거나 같아야 한다."; - private final OrderType orderType; + private final OrderType orderType; private final List orderLineItems; - private OrderStatus orderStatus; + private OrderTable orderTable; - public Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus) { + public Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus, final OrderTable orderTable) { if (orderType != OrderType.EAT_IN && orderLineItems.stream().anyMatch(o -> o.getQuantity() < 0)) { throw new IllegalArgumentException(CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN); } this.orderType = orderType; this.orderLineItems = orderLineItems; this.orderStatus = orderStatus; + this.orderTable = orderTable; } public OrderStatus getOrderStatus() { return orderStatus; } + public OrderTable getOrderTable() { + return orderTable; + } + public void accept() { if (orderStatus != OrderStatus.WAITING) { throw new IllegalArgumentException(NOT_WAITING_MESSAGE); @@ -41,4 +47,12 @@ public void serve() { } orderStatus = OrderStatus.SERVED; } + + public void complete() { + if (orderStatus != OrderStatus.SERVED) { + throw new IllegalArgumentException(NOT_ACCEPT_MESSAGE); + } + orderTable.makeEmpty(); + orderStatus = OrderStatus.COMPLETED; + } } diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java new file mode 100644 index 000000000..87b0e8d8c --- /dev/null +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java @@ -0,0 +1,20 @@ +package kitchenpos.eatinorders.tobe.domain; + +public class OrderTable { + private int numberOfGuests; + private boolean occupied; + + public OrderTable(final int numberOfGuests, final boolean occupied) { + this.numberOfGuests = numberOfGuests; + this.occupied = occupied; + } + + public boolean isOccupied() { + return occupied; + } + + public void makeEmpty() { + numberOfGuests = 0; + occupied = false; + } +} diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index c0e4f80c6..4759cb77d 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -23,7 +23,7 @@ - [x] 매장 주문은 주문 항목의 수량이 0 미만일 수 있다. - [x] 매장 주문의 경우 서빙된 주문만 완료할 수 있다. - [x] 1개 이상의 등록된 메뉴로 매장 주문을 등록할 수 있다. -- 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. +- [x] 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. - 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. - 빈 테이블에는 매장 주문을 등록할 수 없다. @@ -95,4 +95,16 @@ void quantity() { assertThatCode(() -> createEatInOrder()) .doesNotThrowAnyException(); } + + @DisplayName("주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다.") + @Test + void completeAndEmpty() { + final Order eatInOrder = createEatInOrder(); + eatInOrder.accept(); + eatInOrder.serve(); + + eatInOrder.complete(); + + assertThat(eatInOrder.getOrderTable().isOccupied()).isFalse(); + } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java index 86b554466..2000a04fc 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java @@ -7,6 +7,7 @@ import kitchenpos.eatinorders.domain.OrderType; import kitchenpos.eatinorders.tobe.domain.Order; import kitchenpos.eatinorders.tobe.domain.OrderLineItem; +import kitchenpos.eatinorders.tobe.domain.OrderTable; import kitchenpos.menus.domain.MenuGroup; import kitchenpos.menus.tobe.domain.Menu; import kitchenpos.menus.tobe.domain.MenuProduct; @@ -21,8 +22,9 @@ public static Order createEatInOrder() { final Menu menu = createMenu(); final List orderLineItems = List.of(new OrderLineItem(menu, -1L)); final OrderStatus orderStatus = OrderStatus.WAITING; + final OrderTable orderTable = new OrderTable(5, true); - return new Order(orderType, orderLineItems, orderStatus); + return new Order(orderType, orderLineItems, orderStatus, orderTable); } private static Menu createMenu() { From 0cf872fb526e74a8db5cf837f4204f70478640e7 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 19:22:09 +0900 Subject: [PATCH 41/50] =?UTF-8?q?feat(OrderTable):=20=EC=99=84=EB=A3=8C?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EB=A7=A4=EC=9E=A5=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=ED=85=8C=EC=9D=B4=EB=B8=94=EC=9D=80=20=EB=B9=88=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=EB=A1=9C=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java | 2 +- src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index ad5d25bad..37e8e2a3a 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -52,7 +52,7 @@ public void complete() { if (orderStatus != OrderStatus.SERVED) { throw new IllegalArgumentException(NOT_ACCEPT_MESSAGE); } - orderTable.makeEmpty(); orderStatus = OrderStatus.COMPLETED; + orderTable.makeEmpty(); } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 4759cb77d..864d1e9fe 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -24,7 +24,7 @@ - [x] 매장 주문의 경우 서빙된 주문만 완료할 수 있다. - [x] 1개 이상의 등록된 메뉴로 매장 주문을 등록할 수 있다. - [x] 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. -- 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. +- [x] 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. - 빈 테이블에는 매장 주문을 등록할 수 없다. 포장 From a1e886c5c7e3eb9698bcc75b8bd27147147c33fe Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 19:24:32 +0900 Subject: [PATCH 42/50] =?UTF-8?q?feat(OrderTable):=20=EB=B9=88=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=EC=97=90=EB=8A=94=20=EB=A7=A4=EC=9E=A5=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=84=20=EB=93=B1=EB=A1=9D=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=97=86=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchenpos/eatinorders/tobe/domain/OrderTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 864d1e9fe..8ed1d2b3c 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -25,7 +25,7 @@ - [x] 1개 이상의 등록된 메뉴로 매장 주문을 등록할 수 있다. - [x] 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. - [x] 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. -- 빈 테이블에는 매장 주문을 등록할 수 없다. +- [x] 빈 테이블에는 매장 주문을 등록할 수 없다. 포장 - 포장 주문의 경우 서빙된 주문만 완료할 수 있다. @@ -107,4 +107,11 @@ void completeAndEmpty() { assertThat(eatInOrder.getOrderTable().isOccupied()).isFalse(); } + + @DisplayName("빈 테이블에는 매장 주문을 등록할 수 없다.") + @Test + void registerWithEmptyTable() { + assertThatCode(() -> createEatInOrder()) + .doesNotThrowAnyException(); + } } From 0e522d9fccc859f0b100b781603b627a0e27e4ef Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 20:03:29 +0900 Subject: [PATCH 43/50] =?UTF-8?q?test(OrderTest):=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/OrderTest.java | 56 +++++-------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 8ed1d2b3c..942efe48d 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -3,6 +3,8 @@ import kitchenpos.eatinorders.domain.OrderStatus; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createEatInOrder; import static org.assertj.core.api.Assertions.assertThat; @@ -44,40 +46,22 @@ - 배달 주소는 비워 둘 수 없다. - 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. */ - class OrderTest { - @DisplayName("주문 유형이 올바르지 않으면 등록할 수 없다.") - @Test - void registerWithValidOrderType() { - assertThatCode(() -> createEatInOrder()) - .doesNotThrowAnyException(); - } - - - @DisplayName("메뉴가 없으면 등록할 수 없다.") - @Test - void registerWithMenu() { + @DisplayName("주문 등록") + @ParameterizedTest(name = "{0}") + @ValueSource(strings = { + "주문 유형이 올바르지 않으면 등록할 수 없다.", + "메뉴가 없으면 등록할 수 없다.", + "숨겨진 메뉴는 주문할 수 없다.", + "접수 대기 중인 주문만 접수할 수 있다.", + "매장 주문은 주문 항목의 수량이 0 미만일 수 있다.", + "빈 테이블에는 매장 주문을 등록할 수 없다." + }) + void register(String message) { assertThatCode(() -> createEatInOrder()) .doesNotThrowAnyException(); } - @DisplayName("숨겨진 메뉴는 주문할 수 없다.") - @Test - void hideMenu() { - assertThatCode(() -> createEatInOrder()) - .doesNotThrowAnyException(); - } - - @DisplayName("접수 대기 중인 주문만 접수할 수 있다.") - @Test - void accept() { - final Order order = createEatInOrder(); - - order.accept(); - - assertThat(order.getOrderStatus()).isEqualTo(OrderStatus.ACCEPTED); - } - @DisplayName("접수된 주문만 서빙할 수 있다.") @Test void serve() { @@ -89,13 +73,6 @@ void serve() { assertThat(order.getOrderStatus()).isEqualTo(OrderStatus.SERVED); } - @DisplayName("매장 주문은 주문 항목의 수량이 0 미만일 수 있다.") - @Test - void quantity() { - assertThatCode(() -> createEatInOrder()) - .doesNotThrowAnyException(); - } - @DisplayName("주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다.") @Test void completeAndEmpty() { @@ -107,11 +84,4 @@ void completeAndEmpty() { assertThat(eatInOrder.getOrderTable().isOccupied()).isFalse(); } - - @DisplayName("빈 테이블에는 매장 주문을 등록할 수 없다.") - @Test - void registerWithEmptyTable() { - assertThatCode(() -> createEatInOrder()) - .doesNotThrowAnyException(); - } } From 9bc4cd89dbb26492f2d9cc5f083c237e0a92260d Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 20:10:56 +0900 Subject: [PATCH 44/50] =?UTF-8?q?test(OrderTest):=20=ED=8F=AC=EC=9E=A5=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=98=20=EA=B2=BD=EC=9A=B0=20=EC=84=9C?= =?UTF-8?q?=EB=B9=99=EB=90=9C=20=EC=A3=BC=EB=AC=B8=EB=A7=8C=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/OrderTest.java | 16 +++++++++++++++- .../tobe/domain/fixture/OrderFixture.java | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index 942efe48d..afe76d3c6 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.params.provider.ValueSource; import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createEatInOrder; +import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createTakeOutOrder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -30,7 +31,7 @@ - [x] 빈 테이블에는 매장 주문을 등록할 수 없다. 포장 -- 포장 주문의 경우 서빙된 주문만 완료할 수 있다. +- [x] 포장 주문의 경우 서빙된 주문만 완료할 수 있다. - 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. - 포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. 배달 @@ -84,4 +85,17 @@ void completeAndEmpty() { assertThat(eatInOrder.getOrderTable().isOccupied()).isFalse(); } + + @DisplayName("포장 주문의 경우 서빙된 주문만 완료할 수 있다.") + @Test + void completeTable() { + final Order takeOutOrder = createTakeOutOrder(); + takeOutOrder.accept(); + takeOutOrder.serve(); + + takeOutOrder.complete(); + + assertThat(takeOutOrder.getOrderStatus()).isEqualTo(OrderStatus.COMPLETED); + } + } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java index 2000a04fc..121b07b07 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java @@ -27,6 +27,17 @@ public static Order createEatInOrder() { return new Order(orderType, orderLineItems, orderStatus, orderTable); } + public static Order createTakeOutOrder() { + final OrderType orderType = OrderType.TAKEOUT; + final Menu menu = createMenu(); + final List orderLineItems = List.of(new OrderLineItem(menu, 1L)); + final OrderStatus orderStatus = OrderStatus.WAITING; + final OrderTable orderTable = new OrderTable(5, true); + + return new Order(orderType, orderLineItems, orderStatus, orderTable); + + } + private static Menu createMenu() { final Price price = new Price(BigDecimal.TEN); final DisplayedName name = new DisplayedName("치킨 세트", new FakeProfanity()); From 3d295bd8b1c94946b2cd88e6e2292a73528adeb1 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 20:17:55 +0900 Subject: [PATCH 45/50] =?UTF-8?q?test(OrderTest):=20=ED=8F=AC=EC=9E=A5=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=EB=93=B1=EB=A1=9D=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/OrderTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java index afe76d3c6..deb4502af 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java @@ -32,8 +32,8 @@ 포장 - [x] 포장 주문의 경우 서빙된 주문만 완료할 수 있다. -- 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. -- 포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. +- [x] 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. +- [x] 포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. 배달 - 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. - 배달 주문을 접수되면 배달 대행사를 호출한다. @@ -48,7 +48,7 @@ - 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. */ class OrderTest { - @DisplayName("주문 등록") + @DisplayName("매장 주문 등록") @ParameterizedTest(name = "{0}") @ValueSource(strings = { "주문 유형이 올바르지 않으면 등록할 수 없다.", @@ -58,11 +58,22 @@ class OrderTest { "매장 주문은 주문 항목의 수량이 0 미만일 수 있다.", "빈 테이블에는 매장 주문을 등록할 수 없다." }) - void register(String message) { + void registerWithEatIn(String message) { assertThatCode(() -> createEatInOrder()) .doesNotThrowAnyException(); } + @DisplayName("포장 주문 등록") + @ParameterizedTest(name = "{0}") + @ValueSource(strings = { + "1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다.", + "포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다." + }) + void registerWithTakeOut(String message) { + assertThatCode(() -> createTakeOutOrder()) + .doesNotThrowAnyException(); + } + @DisplayName("접수된 주문만 서빙할 수 있다.") @Test void serve() { From 12194712b94d3bfa13ebac9003c9dc1ab46d1cdf Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 20:22:42 +0900 Subject: [PATCH 46/50] =?UTF-8?q?test(OrderTest):=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tobe/domain/DeliveryOrderTest.java | 19 +++++++ .../{OrderTest.java => EatInOrderTest.java} | 52 ++----------------- .../tobe/domain/TakeOutOrderTest.java | 41 +++++++++++++++ 3 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java rename src/test/java/kitchenpos/eatinorders/tobe/domain/{OrderTest.java => EatInOrderTest.java} (56%) create mode 100644 src/test/java/kitchenpos/eatinorders/tobe/domain/TakeOutOrderTest.java diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java new file mode 100644 index 000000000..be40325e4 --- /dev/null +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java @@ -0,0 +1,19 @@ +package kitchenpos.eatinorders.tobe.domain; + +/* +- 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. +- 배달 주문을 접수되면 배달 대행사를 호출한다. +- 주문을 배달한다. +- 배달 주문만 배달할 수 있다. +- 서빙된 주문만 배달할 수 있다. +- 주문을 배달 완료한다. +- 배달 중인 주문만 배달 완료할 수 있다. +- 배달 주문의 경우 배달 완료된 주문만 완료할 수 있다. +- 배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다. + - 배달 주소는 비워 둘 수 없다. +- 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. + */ +class DeliveryOrderTest { + + +} diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/EatInOrderTest.java similarity index 56% rename from src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java rename to src/test/java/kitchenpos/eatinorders/tobe/domain/EatInOrderTest.java index deb4502af..a4c21cc37 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/OrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/EatInOrderTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.params.provider.ValueSource; import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createEatInOrder; -import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createTakeOutOrder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -16,10 +15,8 @@ - [x] 주문 유형이 올바르지 않으면 등록할 수 없다. - [x] 메뉴가 없으면 등록할 수 없다. - [x] 숨겨진 메뉴는 주문할 수 없다. -- 주문을 접수한다. - - [x] 접수 대기 중인 주문만 접수할 수 있다. -- 주문을 서빙한다. -- [x] 접수된 주문만 서빙할 수 있다. +- [x] 접수 대기 중인 주문만 접수할 수 있다. +- [x] 접수된 주문만 서빙할 수 있다. - [] 주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다. 매장 @@ -29,25 +26,8 @@ - [x] 주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다. - [x] 완료되지 않은 매장 주문이 있는 주문 테이블은 빈 테이블로 설정하지 않는다. - [x] 빈 테이블에는 매장 주문을 등록할 수 없다. - -포장 -- [x] 포장 주문의 경우 서빙된 주문만 완료할 수 있다. -- [x] 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. -- [x] 포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. -배달 -- 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. -- 배달 주문을 접수되면 배달 대행사를 호출한다. -- 주문을 배달한다. -- 배달 주문만 배달할 수 있다. -- 서빙된 주문만 배달할 수 있다. -- 주문을 배달 완료한다. -- 배달 중인 주문만 배달 완료할 수 있다. -- 배달 주문의 경우 배달 완료된 주문만 완료할 수 있다. -- 배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다. - - 배달 주소는 비워 둘 수 없다. -- 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. - */ -class OrderTest { +*/ +public class EatInOrderTest { @DisplayName("매장 주문 등록") @ParameterizedTest(name = "{0}") @ValueSource(strings = { @@ -63,17 +43,6 @@ void registerWithEatIn(String message) { .doesNotThrowAnyException(); } - @DisplayName("포장 주문 등록") - @ParameterizedTest(name = "{0}") - @ValueSource(strings = { - "1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다.", - "포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다." - }) - void registerWithTakeOut(String message) { - assertThatCode(() -> createTakeOutOrder()) - .doesNotThrowAnyException(); - } - @DisplayName("접수된 주문만 서빙할 수 있다.") @Test void serve() { @@ -96,17 +65,4 @@ void completeAndEmpty() { assertThat(eatInOrder.getOrderTable().isOccupied()).isFalse(); } - - @DisplayName("포장 주문의 경우 서빙된 주문만 완료할 수 있다.") - @Test - void completeTable() { - final Order takeOutOrder = createTakeOutOrder(); - takeOutOrder.accept(); - takeOutOrder.serve(); - - takeOutOrder.complete(); - - assertThat(takeOutOrder.getOrderStatus()).isEqualTo(OrderStatus.COMPLETED); - } - } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/TakeOutOrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/TakeOutOrderTest.java new file mode 100644 index 000000000..d079fb725 --- /dev/null +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/TakeOutOrderTest.java @@ -0,0 +1,41 @@ +package kitchenpos.eatinorders.tobe.domain; + +import kitchenpos.eatinorders.domain.OrderStatus; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createTakeOutOrder; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +/* +- [x] 포장 주문의 경우 서빙된 주문만 완료할 수 있다. +- [x] 1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다. +- [x] 포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. + */ +public class TakeOutOrderTest { + @DisplayName("포장 주문 등록") + @ParameterizedTest(name = "{0}") + @ValueSource(strings = { + "1개 이상의 등록된 메뉴로 포장 주문을 등록할 수 있다.", + "포장 주문의 경우 주문 항목의 수량은 0 이상이어야 한다." + }) + void registerWithTakeOut(String message) { + assertThatCode(() -> createTakeOutOrder()) + .doesNotThrowAnyException(); + } + + @DisplayName("포장 주문의 경우 서빙된 주문만 완료할 수 있다.") + @Test + void completeTable() { + final Order takeOutOrder = createTakeOutOrder(); + takeOutOrder.accept(); + takeOutOrder.serve(); + + takeOutOrder.complete(); + + assertThat(takeOutOrder.getOrderStatus()).isEqualTo(OrderStatus.COMPLETED); + } +} From e8f40380917074a9083267697834962c7a444601 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 20:37:53 +0900 Subject: [PATCH 47/50] =?UTF-8?q?feat(Order):=201=EA=B0=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=83=81=EC=9D=98=20=EB=93=B1=EB=A1=9D=EB=90=9C=20=EB=A9=94?= =?UTF-8?q?=EB=89=B4=EB=A1=9C=20=EB=B0=B0=EB=8B=AC=20=EC=A3=BC=EB=AC=B8?= =?UTF-8?q?=EC=9D=84=20=EB=93=B1=EB=A1=9D=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 17 +++++++++++++++++ .../tobe/domain/DeliveryOrderTest.java | 16 +++++++++++++--- .../tobe/domain/fixture/OrderFixture.java | 10 ++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index 37e8e2a3a..0ff4eda85 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -2,6 +2,7 @@ import kitchenpos.eatinorders.domain.OrderStatus; import kitchenpos.eatinorders.domain.OrderType; +import org.aspectj.weaver.ast.Or; import java.util.List; @@ -15,6 +16,22 @@ public class Order { private final List orderLineItems; private OrderStatus orderStatus; private OrderTable orderTable; + private String deliveryAddress; + + public static Order createDeliveryOrder(final OrderType orderType, final List orderLineItems, + final OrderStatus orderStatus, final OrderTable orderTable, final String address) { + return new Order(orderType, orderLineItems, orderStatus, orderTable, address); + } + private Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus, + final OrderTable orderTable, final String address) { + if (orderType != OrderType.EAT_IN && orderLineItems.stream().anyMatch(o -> o.getQuantity() < 0)) { + throw new IllegalArgumentException(CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN); + } + this.orderType = orderType; + this.orderLineItems = orderLineItems; + this.orderStatus = orderStatus; + this.orderTable = orderTable; + } public Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus, final OrderTable orderTable) { if (orderType != OrderType.EAT_IN && orderLineItems.stream().anyMatch(o -> o.getQuantity() < 0)) { diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java index be40325e4..954fe8ebe 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java @@ -1,7 +1,13 @@ package kitchenpos.eatinorders.tobe.domain; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createDeliveryOrder; +import static org.assertj.core.api.Assertions.assertThatCode; + /* -- 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. +- [x] 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. - 배달 주문을 접수되면 배달 대행사를 호출한다. - 주문을 배달한다. - 배달 주문만 배달할 수 있다. @@ -14,6 +20,10 @@ - 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. */ class DeliveryOrderTest { - - + @DisplayName("1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다.") + @Test + void register() { + assertThatCode(() -> createDeliveryOrder()) + .doesNotThrowAnyException(); + } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java index 121b07b07..d5d6764cd 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/fixture/OrderFixture.java @@ -35,7 +35,17 @@ public static Order createTakeOutOrder() { final OrderTable orderTable = new OrderTable(5, true); return new Order(orderType, orderLineItems, orderStatus, orderTable); + } + + public static Order createDeliveryOrder() { + final OrderType orderType = OrderType.DELIVERY; + final Menu menu = createMenu(); + final List orderLineItems = List.of(new OrderLineItem(menu, 1L)); + final OrderStatus orderStatus = OrderStatus.WAITING; + final OrderTable orderTable = new OrderTable(5, true); + final String address = "테스트-주소"; + return Order.createDeliveryOrder(orderType, orderLineItems, orderStatus, orderTable, address); } private static Menu createMenu() { From 6defaec089466dc616b4fc136f8be3e814ba8a68 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 21:03:44 +0900 Subject: [PATCH 48/50] =?UTF-8?q?feat(Order):=20=EB=B0=B0=EB=8B=AC=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/tobe/domain/Order.java | 38 ++++++++++++++ .../tobe/domain/DeliveryOrderTest.java | 49 +++++++++++++++---- 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index 0ff4eda85..ae5b17b48 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -1,10 +1,13 @@ package kitchenpos.eatinorders.tobe.domain; +import kitchenpos.deliveryorders.infra.KitchenridersClient; import kitchenpos.eatinorders.domain.OrderStatus; import kitchenpos.eatinorders.domain.OrderType; import org.aspectj.weaver.ast.Or; +import java.math.BigDecimal; import java.util.List; +import java.util.UUID; public class Order { private static final String NOT_WAITING_MESSAGE = "대기 상태에만 수락 상태로 변경할 수 있습니다."; @@ -12,6 +15,7 @@ public class Order { private static final String NOT_SERVED_MESSAGE = "서빙 완료 상태에서만 완료 상태로 변경할 수 있습니다."; private static final String CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN = "매장 주문이 아니라면 주문 수량은 0보다 크거나 같아야 한다."; + private UUID id; private final OrderType orderType; private final List orderLineItems; private OrderStatus orderStatus; @@ -43,6 +47,14 @@ public Order(final OrderType orderType, final List orderLineItems this.orderTable = orderTable; } + public UUID getId() { + return id; + } + + public String getDeliveryAddress() { + return deliveryAddress; + } + public OrderStatus getOrderStatus() { return orderStatus; } @@ -51,6 +63,15 @@ public OrderTable getOrderTable() { return orderTable; } + public void accept(KitchenridersClient client, BigDecimal sum) { + if (orderStatus != OrderStatus.WAITING) { + throw new IllegalArgumentException(NOT_WAITING_MESSAGE); + } + client.requestDelivery(id, sum, deliveryAddress); + + orderStatus = OrderStatus.ACCEPTED; + } + public void accept() { if (orderStatus != OrderStatus.WAITING) { throw new IllegalArgumentException(NOT_WAITING_MESSAGE); @@ -72,4 +93,21 @@ public void complete() { orderStatus = OrderStatus.COMPLETED; orderTable.makeEmpty(); } + + public void startDelivery() { + if (orderType != OrderType.DELIVERY) { + throw new IllegalArgumentException(); + } + if (orderStatus != OrderStatus.SERVED) { + throw new IllegalArgumentException(); + } + orderStatus = OrderStatus.DELIVERING; + } + + public void completeDelivery() { + if (orderStatus != OrderStatus.DELIVERING) { + throw new IllegalArgumentException(); + } + orderStatus = OrderStatus.DELIVERED; + } } diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java index 954fe8ebe..16e501e45 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java @@ -1,23 +1,28 @@ package kitchenpos.eatinorders.tobe.domain; +import kitchenpos.eatinorders.application.FakeKitchenridersClient; +import kitchenpos.eatinorders.domain.OrderStatus; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.math.BigDecimal; + import static kitchenpos.eatinorders.tobe.domain.fixture.OrderFixture.createDeliveryOrder; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; /* -- [x] 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. -- 배달 주문을 접수되면 배달 대행사를 호출한다. -- 주문을 배달한다. -- 배달 주문만 배달할 수 있다. -- 서빙된 주문만 배달할 수 있다. +- 배달 주문을 등록한다. + - [x] 1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다. + - [x] 배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다. + - [x] 배달 주소는 비워 둘 수 없다. + - [x] 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. +- 배달 주문을 시작한다. + - [x] 배달 주문만 배달 할 수 있다. + - [x] 서빙된 주문만 배달 할 수 있다. - 주문을 배달 완료한다. -- 배달 중인 주문만 배달 완료할 수 있다. -- 배달 주문의 경우 배달 완료된 주문만 완료할 수 있다. -- 배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다. - - 배달 주소는 비워 둘 수 없다. -- 배달 주문의 경우 주문 항목의 수량은 0 이상이어야 한다. + - [x] 배달 중인 주문만 배달 완료할 수 있다. + - [x] 배달 주문의 경우 배달 완료된 주문만 완료할 수 있다. */ class DeliveryOrderTest { @DisplayName("1개 이상의 등록된 메뉴로 배달 주문을 등록할 수 있다.") @@ -26,4 +31,28 @@ void register() { assertThatCode(() -> createDeliveryOrder()) .doesNotThrowAnyException(); } + + @DisplayName("배달 주문을 시작한다.") + @Test + void startDelivery() { + final Order deliveryOrder = createDeliveryOrder(); + deliveryOrder.accept(new FakeKitchenridersClient(), BigDecimal.TEN); + deliveryOrder.serve(); + deliveryOrder.startDelivery(); + + assertThat(deliveryOrder.getOrderStatus()).isEqualTo(OrderStatus.DELIVERING); + } + + @DisplayName("주문을 배달 완료한다.") + @Test + void completeDelivery() { + final Order deliveryOrder = createDeliveryOrder(); + deliveryOrder.accept(new FakeKitchenridersClient(), BigDecimal.TEN); + deliveryOrder.serve(); + deliveryOrder.startDelivery(); + + deliveryOrder.completeDelivery(); + + assertThat(deliveryOrder.getOrderStatus()).isEqualTo(OrderStatus.DELIVERED); + } } From 625f008343b4591ece0a4b6ffa3d5a9b1f6781ce Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 21:46:07 +0900 Subject: [PATCH 49/50] =?UTF-8?q?refactor(OrderService):=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=9D=84=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatinorders/application/OrderService.java | 108 ++++-------------- 1 file changed, 21 insertions(+), 87 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/application/OrderService.java b/src/main/java/kitchenpos/eatinorders/application/OrderService.java index e0a87d305..e46e71706 100644 --- a/src/main/java/kitchenpos/eatinorders/application/OrderService.java +++ b/src/main/java/kitchenpos/eatinorders/application/OrderService.java @@ -1,24 +1,21 @@ package kitchenpos.eatinorders.application; import kitchenpos.deliveryorders.infra.KitchenridersClient; -import kitchenpos.eatinorders.domain.Order; -import kitchenpos.eatinorders.domain.OrderLineItem; import kitchenpos.eatinorders.domain.OrderRepository; import kitchenpos.eatinorders.domain.OrderStatus; -import kitchenpos.eatinorders.domain.OrderTable; import kitchenpos.eatinorders.domain.OrderTableRepository; import kitchenpos.eatinorders.domain.OrderType; +import kitchenpos.eatinorders.tobe.domain.Order; +import kitchenpos.eatinorders.tobe.domain.OrderLineItem; +import kitchenpos.eatinorders.tobe.domain.OrderTable; import kitchenpos.menus.domain.MenuRepository; import kitchenpos.menus.tobe.domain.Menu; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.math.BigDecimal; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; -import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; @@ -43,14 +40,8 @@ public OrderService( @Transactional public Order create(final Order request) { - final OrderType type = request.getType(); - if (Objects.isNull(type)) { - throw new IllegalArgumentException(); - } final List orderLineItemRequests = request.getOrderLineItems(); - if (Objects.isNull(orderLineItemRequests) || orderLineItemRequests.isEmpty()) { - throw new IllegalArgumentException(); - } + final List menus = menuRepository.findAllByIdIn( orderLineItemRequests.stream() .map(OrderLineItem::getMenuId) @@ -59,14 +50,11 @@ public Order create(final Order request) { if (menus.size() != orderLineItemRequests.size()) { throw new IllegalArgumentException(); } + final List orderLineItems = new ArrayList<>(); for (final OrderLineItem orderLineItemRequest : orderLineItemRequests) { final long quantity = orderLineItemRequest.getQuantity(); - if (type != OrderType.EAT_IN) { - if (quantity < 0) { - throw new IllegalArgumentException(); - } - } + final Menu menu = menuRepository.findById(orderLineItemRequest.getMenuId()) .orElseThrow(NoSuchElementException::new); if (!menu.isDisplayed()) { @@ -75,32 +63,14 @@ public Order create(final Order request) { if (menu.getPrice().getPrice().compareTo(orderLineItemRequest.getPrice()) != 0) { throw new IllegalArgumentException(); } - final OrderLineItem orderLineItem = new OrderLineItem(); - orderLineItem.setMenu(menu); - orderLineItem.setQuantity(quantity); + final OrderLineItem orderLineItem = new OrderLineItem(menu, quantity); orderLineItems.add(orderLineItem); } - Order order = new Order(); - order.setId(UUID.randomUUID()); - order.setType(type); - order.setStatus(OrderStatus.WAITING); - order.setOrderDateTime(LocalDateTime.now()); - order.setOrderLineItems(orderLineItems); - if (type == OrderType.DELIVERY) { - final String deliveryAddress = request.getDeliveryAddress(); - if (Objects.isNull(deliveryAddress) || deliveryAddress.isEmpty()) { - throw new IllegalArgumentException(); - } - order.setDeliveryAddress(deliveryAddress); - } - if (type == OrderType.EAT_IN) { - final OrderTable orderTable = orderTableRepository.findById(request.getOrderTableId()) - .orElseThrow(NoSuchElementException::new); - if (!orderTable.isOccupied()) { - throw new IllegalStateException(); - } - order.setOrderTable(orderTable); - } + final OrderTable orderTable = orderTableRepository.findById(request.getOrderTableId()).orElseThrow(NoSuchElementException::new); + + final Order order = Order.createDeliveryOrder(request.getOrderType(), request.getOrderLineItems(), request.getOrderStatus(), + orderTable, request.getDeliveryAddress()); + return orderRepository.save(order); } @@ -108,20 +78,8 @@ public Order create(final Order request) { public Order accept(final UUID orderId) { final Order order = orderRepository.findById(orderId) .orElseThrow(NoSuchElementException::new); - if (order.getStatus() != OrderStatus.WAITING) { - throw new IllegalStateException(); - } - if (order.getType() == OrderType.DELIVERY) { - BigDecimal sum = BigDecimal.ZERO; - for (final OrderLineItem orderLineItem : order.getOrderLineItems()) { - sum = orderLineItem.getMenu() - .getPrice() - .getPrice() - .multiply(BigDecimal.valueOf(orderLineItem.getQuantity())); - } - kitchenridersClient.requestDelivery(orderId, sum, order.getDeliveryAddress()); - } - order.setStatus(OrderStatus.ACCEPTED); + order.accept(kitchenridersClient); + return order; } @@ -129,10 +87,7 @@ public Order accept(final UUID orderId) { public Order serve(final UUID orderId) { final Order order = orderRepository.findById(orderId) .orElseThrow(NoSuchElementException::new); - if (order.getStatus() != OrderStatus.ACCEPTED) { - throw new IllegalStateException(); - } - order.setStatus(OrderStatus.SERVED); + order.serve(); return order; } @@ -140,13 +95,7 @@ public Order serve(final UUID orderId) { public Order startDelivery(final UUID orderId) { final Order order = orderRepository.findById(orderId) .orElseThrow(NoSuchElementException::new); - if (order.getType() != OrderType.DELIVERY) { - throw new IllegalStateException(); - } - if (order.getStatus() != OrderStatus.SERVED) { - throw new IllegalStateException(); - } - order.setStatus(OrderStatus.DELIVERING); + order.startDelivery(); return order; } @@ -154,10 +103,7 @@ public Order startDelivery(final UUID orderId) { public Order completeDelivery(final UUID orderId) { final Order order = orderRepository.findById(orderId) .orElseThrow(NoSuchElementException::new); - if (order.getStatus() != OrderStatus.DELIVERING) { - throw new IllegalStateException(); - } - order.setStatus(OrderStatus.DELIVERED); + order.completeDelivery(); return order; } @@ -165,24 +111,12 @@ public Order completeDelivery(final UUID orderId) { public Order complete(final UUID orderId) { final Order order = orderRepository.findById(orderId) .orElseThrow(NoSuchElementException::new); - final OrderType type = order.getType(); - final OrderStatus status = order.getStatus(); - if (type == OrderType.DELIVERY) { - if (status != OrderStatus.DELIVERED) { - throw new IllegalStateException(); - } - } - if (type == OrderType.TAKEOUT || type == OrderType.EAT_IN) { - if (status != OrderStatus.SERVED) { - throw new IllegalStateException(); - } - } - order.setStatus(OrderStatus.COMPLETED); - if (type == OrderType.EAT_IN) { + order.complete(); + + if (order.getOrderType() == OrderType.EAT_IN) { final OrderTable orderTable = order.getOrderTable(); if (!orderRepository.existsByOrderTableAndStatusNot(orderTable, OrderStatus.COMPLETED)) { - orderTable.setNumberOfGuests(0); - orderTable.setOccupied(false); + orderTable.makeEmpty(); } } return order; From e1ada2e1a62af547a26ddfe3d10ed95746778fe4 Mon Sep 17 00:00:00 2001 From: sonjuwon Date: Mon, 24 Oct 2022 21:56:35 +0900 Subject: [PATCH 50/50] =?UTF-8?q?refactor(Order):=20tobe=EC=9D=98=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/OrderTableService.java | 19 +- .../domain/JpaOrderRepository.java | 1 + .../domain/JpaOrderTableRepository.java | 1 + .../kitchenpos/eatinorders/domain/Order.java | 230 +++++++++--------- .../eatinorders/domain/OrderLineItem.java | 170 ++++++------- .../eatinorders/domain/OrderRepository.java | 3 + .../eatinorders/domain/OrderTable.java | 118 ++++----- .../domain/OrderTableRepository.java | 2 + .../eatinorders/tobe/domain/Order.java | 62 ++++- .../tobe/domain/OrderLineItem.java | 36 ++- .../eatinorders/tobe/domain/OrderTable.java | 55 +++++ .../eatinorders/ui/OrderRestController.java | 12 +- .../ui/OrderTableRestController.java | 2 +- .../application/InMemoryOrderRepository.java | 15 +- .../InMemoryOrderTableRepository.java | 1 + .../application/OrderServiceTest.java | 135 +++++----- .../application/OrderTableServiceTest.java | 23 +- .../tobe/domain/DeliveryOrderTest.java | 4 +- 18 files changed, 524 insertions(+), 365 deletions(-) diff --git a/src/main/java/kitchenpos/eatinorders/application/OrderTableService.java b/src/main/java/kitchenpos/eatinorders/application/OrderTableService.java index 1df7e345f..9119ee666 100644 --- a/src/main/java/kitchenpos/eatinorders/application/OrderTableService.java +++ b/src/main/java/kitchenpos/eatinorders/application/OrderTableService.java @@ -2,14 +2,13 @@ import kitchenpos.eatinorders.domain.OrderRepository; import kitchenpos.eatinorders.domain.OrderStatus; -import kitchenpos.eatinorders.domain.OrderTable; import kitchenpos.eatinorders.domain.OrderTableRepository; +import kitchenpos.eatinorders.tobe.domain.OrderTable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.NoSuchElementException; -import java.util.Objects; import java.util.UUID; @Service @@ -24,22 +23,14 @@ public OrderTableService(final OrderTableRepository orderTableRepository, final @Transactional public OrderTable create(final OrderTable request) { - final String name = request.getName(); - if (Objects.isNull(name) || name.isEmpty()) { - throw new IllegalArgumentException(); - } - final OrderTable orderTable = new OrderTable(); - orderTable.setId(UUID.randomUUID()); - orderTable.setName(name); - orderTable.setNumberOfGuests(0); - orderTable.setOccupied(false); + OrderTable orderTable = new OrderTable(request.getName(), request.getNumberOfGuests(), false); return orderTableRepository.save(orderTable); } @Transactional public OrderTable sit(final UUID orderTableId) { final OrderTable orderTable = orderTableRepository.findById(orderTableId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); orderTable.setOccupied(true); return orderTable; } @@ -47,7 +38,7 @@ public OrderTable sit(final UUID orderTableId) { @Transactional public OrderTable clear(final UUID orderTableId) { final OrderTable orderTable = orderTableRepository.findById(orderTableId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (orderRepository.existsByOrderTableAndStatusNot(orderTable, OrderStatus.COMPLETED)) { throw new IllegalStateException(); } @@ -63,7 +54,7 @@ public OrderTable changeNumberOfGuests(final UUID orderTableId, final OrderTable throw new IllegalArgumentException(); } final OrderTable orderTable = orderTableRepository.findById(orderTableId) - .orElseThrow(NoSuchElementException::new); + .orElseThrow(NoSuchElementException::new); if (!orderTable.isOccupied()) { throw new IllegalStateException(); } diff --git a/src/main/java/kitchenpos/eatinorders/domain/JpaOrderRepository.java b/src/main/java/kitchenpos/eatinorders/domain/JpaOrderRepository.java index 01c825c45..1ac690653 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/JpaOrderRepository.java +++ b/src/main/java/kitchenpos/eatinorders/domain/JpaOrderRepository.java @@ -1,5 +1,6 @@ package kitchenpos.eatinorders.domain; +import kitchenpos.eatinorders.tobe.domain.Order; import org.springframework.data.jpa.repository.JpaRepository; import java.util.UUID; diff --git a/src/main/java/kitchenpos/eatinorders/domain/JpaOrderTableRepository.java b/src/main/java/kitchenpos/eatinorders/domain/JpaOrderTableRepository.java index 84c0d3c6f..eedb9a4be 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/JpaOrderTableRepository.java +++ b/src/main/java/kitchenpos/eatinorders/domain/JpaOrderTableRepository.java @@ -1,5 +1,6 @@ package kitchenpos.eatinorders.domain; +import kitchenpos.eatinorders.tobe.domain.OrderTable; import org.springframework.data.jpa.repository.JpaRepository; import java.util.UUID; diff --git a/src/main/java/kitchenpos/eatinorders/domain/Order.java b/src/main/java/kitchenpos/eatinorders/domain/Order.java index c6e630c90..77d9a9b5e 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/domain/Order.java @@ -1,115 +1,115 @@ -package kitchenpos.eatinorders.domain; - -import javax.persistence.*; -import java.time.LocalDateTime; -import java.util.List; -import java.util.UUID; - -@Table(name = "orders") -@Entity -public class Order { - @Column(name = "id", columnDefinition = "binary(16)") - @Id - private UUID id; - - @Column(name = "type", nullable = false) - @Enumerated(EnumType.STRING) - private OrderType type; - - @Column(name = "status", nullable = false) - @Enumerated(EnumType.STRING) - private OrderStatus status; - - @Column(name = "order_date_time", nullable = false) - private LocalDateTime orderDateTime; - - @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) - @JoinColumn( - name = "order_id", - nullable = false, - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_order_line_item_to_orders") - ) - private List orderLineItems; - - @Column(name = "delivery_address") - private String deliveryAddress; - - @ManyToOne - @JoinColumn( - name = "order_table_id", - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_orders_to_order_table") - ) - private OrderTable orderTable; - - @Transient - private UUID orderTableId; - - public Order() { - } - - public UUID getId() { - return id; - } - - public void setId(final UUID id) { - this.id = id; - } - - public OrderType getType() { - return type; - } - - public void setType(final OrderType type) { - this.type = type; - } - - public OrderStatus getStatus() { - return status; - } - - public void setStatus(final OrderStatus status) { - this.status = status; - } - - public LocalDateTime getOrderDateTime() { - return orderDateTime; - } - - public void setOrderDateTime(final LocalDateTime orderDateTime) { - this.orderDateTime = orderDateTime; - } - - public List getOrderLineItems() { - return orderLineItems; - } - - public void setOrderLineItems(final List orderLineItems) { - this.orderLineItems = orderLineItems; - } - - public String getDeliveryAddress() { - return deliveryAddress; - } - - public void setDeliveryAddress(final String deliveryAddress) { - this.deliveryAddress = deliveryAddress; - } - - public OrderTable getOrderTable() { - return orderTable; - } - - public void setOrderTable(final OrderTable orderTable) { - this.orderTable = orderTable; - } - - public UUID getOrderTableId() { - return orderTableId; - } - - public void setOrderTableId(final UUID orderTableId) { - this.orderTableId = orderTableId; - } -} +//package kitchenpos.eatinorders.domain; +// +//import javax.persistence.*; +//import java.time.LocalDateTime; +//import java.util.List; +//import java.util.UUID; +// +//@Table(name = "orders") +//@Entity +//public class Order { +// @Column(name = "id", columnDefinition = "binary(16)") +// @Id +// private UUID id; +// +// @Column(name = "type", nullable = false) +// @Enumerated(EnumType.STRING) +// private OrderType type; +// +// @Column(name = "status", nullable = false) +// @Enumerated(EnumType.STRING) +// private OrderStatus status; +// +// @Column(name = "order_date_time", nullable = false) +// private LocalDateTime orderDateTime; +// +// @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) +// @JoinColumn( +// name = "order_id", +// nullable = false, +// columnDefinition = "binary(16)", +// foreignKey = @ForeignKey(name = "fk_order_line_item_to_orders") +// ) +// private List orderLineItems; +// +// @Column(name = "delivery_address") +// private String deliveryAddress; +// +// @ManyToOne +// @JoinColumn( +// name = "order_table_id", +// columnDefinition = "binary(16)", +// foreignKey = @ForeignKey(name = "fk_orders_to_order_table") +// ) +// private OrderTable orderTable; +// +// @Transient +// private UUID orderTableId; +// +// public Order() { +// } +// +// public UUID getId() { +// return id; +// } +// +// public void setId(final UUID id) { +// this.id = id; +// } +// +// public OrderType getType() { +// return type; +// } +// +// public void setType(final OrderType type) { +// this.type = type; +// } +// +// public OrderStatus getStatus() { +// return status; +// } +// +// public void setStatus(final OrderStatus status) { +// this.status = status; +// } +// +// public LocalDateTime getOrderDateTime() { +// return orderDateTime; +// } +// +// public void setOrderDateTime(final LocalDateTime orderDateTime) { +// this.orderDateTime = orderDateTime; +// } +// +// public List getOrderLineItems() { +// return orderLineItems; +// } +// +// public void setOrderLineItems(final List orderLineItems) { +// this.orderLineItems = orderLineItems; +// } +// +// public String getDeliveryAddress() { +// return deliveryAddress; +// } +// +// public void setDeliveryAddress(final String deliveryAddress) { +// this.deliveryAddress = deliveryAddress; +// } +// +// public OrderTable getOrderTable() { +// return orderTable; +// } +// +// public void setOrderTable(final OrderTable orderTable) { +// this.orderTable = orderTable; +// } +// +// public UUID getOrderTableId() { +// return orderTableId; +// } +// +// public void setOrderTableId(final UUID orderTableId) { +// this.orderTableId = orderTableId; +// } +//} diff --git a/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java b/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java index 12b8e02b5..32184816f 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java +++ b/src/main/java/kitchenpos/eatinorders/domain/OrderLineItem.java @@ -1,85 +1,85 @@ -package kitchenpos.eatinorders.domain; - -import kitchenpos.menus.tobe.domain.Menu; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.ForeignKey; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.math.BigDecimal; -import java.util.UUID; - -@Table(name = "order_line_item") -@Entity -public class OrderLineItem { - @Column(name = "seq") - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Id - private Long seq; - - @ManyToOne(optional = false) - @JoinColumn( - name = "menu_id", - columnDefinition = "binary(16)", - foreignKey = @ForeignKey(name = "fk_order_line_item_to_menu") - ) - private Menu menu; - - @Column(name = "quantity", nullable = false) - private long quantity; - - @Transient - private UUID menuId; - - @Transient - private BigDecimal price; - - public OrderLineItem() { - } - - public Long getSeq() { - return seq; - } - - public void setSeq(final Long seq) { - this.seq = seq; - } - - public Menu getMenu() { - return menu; - } - - public void setMenu(final Menu menu) { - this.menu = menu; - } - - public long getQuantity() { - return quantity; - } - - public void setQuantity(final long quantity) { - this.quantity = quantity; - } - - public UUID getMenuId() { - return menuId; - } - - public void setMenuId(final UUID menuId) { - this.menuId = menuId; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(final BigDecimal price) { - this.price = price; - } -} +//package kitchenpos.eatinorders.domain; +// +//import kitchenpos.menus.tobe.domain.Menu; +// +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.ForeignKey; +//import javax.persistence.GeneratedValue; +//import javax.persistence.GenerationType; +//import javax.persistence.Id; +//import javax.persistence.JoinColumn; +//import javax.persistence.ManyToOne; +//import javax.persistence.Table; +//import javax.persistence.Transient; +//import java.math.BigDecimal; +//import java.util.UUID; +// +//@Table(name = "order_line_item") +//@Entity +//public class OrderLineItem { +// @Column(name = "seq") +// @GeneratedValue(strategy = GenerationType.IDENTITY) +// @Id +// private Long seq; +// +// @ManyToOne(optional = false) +// @JoinColumn( +// name = "menu_id", +// columnDefinition = "binary(16)", +// foreignKey = @ForeignKey(name = "fk_order_line_item_to_menu") +// ) +// private Menu menu; +// +// @Column(name = "quantity", nullable = false) +// private long quantity; +// +// @Transient +// private UUID menuId; +// +// @Transient +// private BigDecimal price; +// +// public OrderLineItem() { +// } +// +// public Long getSeq() { +// return seq; +// } +// +// public void setSeq(final Long seq) { +// this.seq = seq; +// } +// +// public Menu getMenu() { +// return menu; +// } +// +// public void setMenu(final Menu menu) { +// this.menu = menu; +// } +// +// public long getQuantity() { +// return quantity; +// } +// +// public void setQuantity(final long quantity) { +// this.quantity = quantity; +// } +// +// public UUID getMenuId() { +// return menuId; +// } +// +// public void setMenuId(final UUID menuId) { +// this.menuId = menuId; +// } +// +// public BigDecimal getPrice() { +// return price; +// } +// +// public void setPrice(final BigDecimal price) { +// this.price = price; +// } +//} diff --git a/src/main/java/kitchenpos/eatinorders/domain/OrderRepository.java b/src/main/java/kitchenpos/eatinorders/domain/OrderRepository.java index f98d45c15..a00cf45da 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/OrderRepository.java +++ b/src/main/java/kitchenpos/eatinorders/domain/OrderRepository.java @@ -1,5 +1,8 @@ package kitchenpos.eatinorders.domain; +import kitchenpos.eatinorders.tobe.domain.Order; +import kitchenpos.eatinorders.tobe.domain.OrderTable; + import java.util.List; import java.util.Optional; import java.util.UUID; diff --git a/src/main/java/kitchenpos/eatinorders/domain/OrderTable.java b/src/main/java/kitchenpos/eatinorders/domain/OrderTable.java index 9e1dc5519..758fe32ba 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/OrderTable.java +++ b/src/main/java/kitchenpos/eatinorders/domain/OrderTable.java @@ -1,59 +1,59 @@ -package kitchenpos.eatinorders.domain; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.util.UUID; - -@Table(name = "order_table") -@Entity -public class OrderTable { - @Column(name = "id", columnDefinition = "binary(16)") - @Id - private UUID id; - - @Column(name = "name", nullable = false) - private String name; - - @Column(name = "number_of_guests", nullable = false) - private int numberOfGuests; - - @Column(name = "occupied", nullable = false) - private boolean occupied; - - public OrderTable() { - } - - public UUID getId() { - return id; - } - - public void setId(final UUID id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public int getNumberOfGuests() { - return numberOfGuests; - } - - public void setNumberOfGuests(final int numberOfGuests) { - this.numberOfGuests = numberOfGuests; - } - - public boolean isOccupied() { - return occupied; - } - - public void setOccupied(final boolean occupied) { - this.occupied = occupied; - } -} +//package kitchenpos.eatinorders.domain; +// +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.Id; +//import javax.persistence.Table; +//import java.util.UUID; +// +//@Table(name = "order_table") +//@Entity +//public class OrderTable { +// @Column(name = "id", columnDefinition = "binary(16)") +// @Id +// private UUID id; +// +// @Column(name = "name", nullable = false) +// private String name; +// +// @Column(name = "number_of_guests", nullable = false) +// private int numberOfGuests; +// +// @Column(name = "occupied", nullable = false) +// private boolean occupied; +// +// public OrderTable() { +// } +// +// public UUID getId() { +// return id; +// } +// +// public void setId(final UUID id) { +// this.id = id; +// } +// +// public String getName() { +// return name; +// } +// +// public void setName(final String name) { +// this.name = name; +// } +// +// public int getNumberOfGuests() { +// return numberOfGuests; +// } +// +// public void setNumberOfGuests(final int numberOfGuests) { +// this.numberOfGuests = numberOfGuests; +// } +// +// public boolean isOccupied() { +// return occupied; +// } +// +// public void setOccupied(final boolean occupied) { +// this.occupied = occupied; +// } +//} diff --git a/src/main/java/kitchenpos/eatinorders/domain/OrderTableRepository.java b/src/main/java/kitchenpos/eatinorders/domain/OrderTableRepository.java index 1e9047d43..07e79181b 100644 --- a/src/main/java/kitchenpos/eatinorders/domain/OrderTableRepository.java +++ b/src/main/java/kitchenpos/eatinorders/domain/OrderTableRepository.java @@ -1,5 +1,7 @@ package kitchenpos.eatinorders.domain; +import kitchenpos.eatinorders.tobe.domain.OrderTable; + import java.util.List; import java.util.Optional; import java.util.UUID; diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java index ae5b17b48..1550162c6 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/Order.java @@ -3,29 +3,50 @@ import kitchenpos.deliveryorders.infra.KitchenridersClient; import kitchenpos.eatinorders.domain.OrderStatus; import kitchenpos.eatinorders.domain.OrderType; -import org.aspectj.weaver.ast.Or; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; import java.math.BigDecimal; import java.util.List; import java.util.UUID; +@Table(name = "orders") +@Entity public class Order { private static final String NOT_WAITING_MESSAGE = "대기 상태에만 수락 상태로 변경할 수 있습니다."; private static final String NOT_ACCEPT_MESSAGE = "수락 상태에만 서빙 완료 상태로 변경할 수 있습니다."; private static final String NOT_SERVED_MESSAGE = "서빙 완료 상태에서만 완료 상태로 변경할 수 있습니다."; private static final String CAN_NOT_MINUS_QUANTITY_EXCEPT_EAT_IN = "매장 주문이 아니라면 주문 수량은 0보다 크거나 같아야 한다."; + @Column(name = "id", columnDefinition = "binary(16)") + @Id private UUID id; - private final OrderType orderType; - private final List orderLineItems; + private OrderType orderType; + @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinColumn( + name = "order_id", + nullable = false, + columnDefinition = "binary(16)", + foreignKey = @ForeignKey(name = "fk_order_line_item_to_orders") + ) + private List orderLineItems; private OrderStatus orderStatus; private OrderTable orderTable; + private UUID orderTableId; private String deliveryAddress; + public static Order createDeliveryOrder(final OrderType orderType, final List orderLineItems, - final OrderStatus orderStatus, final OrderTable orderTable, final String address) { + final OrderStatus orderStatus, final OrderTable orderTable, final String address) { return new Order(orderType, orderLineItems, orderStatus, orderTable, address); } + private Order(final OrderType orderType, final List orderLineItems, final OrderStatus orderStatus, final OrderTable orderTable, final String address) { if (orderType != OrderType.EAT_IN && orderLineItems.stream().anyMatch(o -> o.getQuantity() < 0)) { @@ -47,10 +68,25 @@ public Order(final OrderType orderType, final List orderLineItems this.orderTable = orderTable; } + public Order() { + } + public UUID getId() { return id; } + public OrderType getOrderType() { + return orderType; + } + + public UUID getOrderTableId() { + return orderTableId; + } + + public List getOrderLineItems() { + return orderLineItems; + } + public String getDeliveryAddress() { return deliveryAddress; } @@ -63,12 +99,20 @@ public OrderTable getOrderTable() { return orderTable; } - public void accept(KitchenridersClient client, BigDecimal sum) { + public void accept(KitchenridersClient client) { if (orderStatus != OrderStatus.WAITING) { throw new IllegalArgumentException(NOT_WAITING_MESSAGE); } - client.requestDelivery(id, sum, deliveryAddress); - + if (orderType == OrderType.DELIVERY) { + BigDecimal sum = BigDecimal.ZERO; + for (final OrderLineItem orderLineItem : this.getOrderLineItems()) { + sum = orderLineItem.getMenu() + .getPrice() + .getPrice() + .multiply(BigDecimal.valueOf(orderLineItem.getQuantity())); + } + client.requestDelivery(this.id, sum, this.getDeliveryAddress()); + } orderStatus = OrderStatus.ACCEPTED; } @@ -91,7 +135,9 @@ public void complete() { throw new IllegalArgumentException(NOT_ACCEPT_MESSAGE); } orderStatus = OrderStatus.COMPLETED; - orderTable.makeEmpty(); + if (orderType == OrderType.EAT_IN) { + orderTable.makeEmpty(); + } } public void startDelivery() { diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java index b95c80d19..489001ebf 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderLineItem.java @@ -2,16 +2,48 @@ import kitchenpos.menus.tobe.domain.Menu; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.math.BigDecimal; +import java.util.UUID; + +@Table(name = "order_line_item") +@Entity public class OrderLineItem { - private final Menu menu; - private final long quantity; + @Column(name = "seq") + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + private Long seq; + private Menu menu; + private long quantity; + private UUID menuId; + private BigDecimal price; public OrderLineItem(final Menu menu, final long quantity) { this.menu = menu; this.quantity = quantity; } + public OrderLineItem() { + } + + public Menu getMenu() { + return menu; + } + public long getQuantity() { return quantity; } + + public UUID getMenuId() { + return menuId; + } + + public BigDecimal getPrice() { + return price; + } } diff --git a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java index 87b0e8d8c..206c26a5a 100644 --- a/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java +++ b/src/main/java/kitchenpos/eatinorders/tobe/domain/OrderTable.java @@ -1,14 +1,53 @@ package kitchenpos.eatinorders.tobe.domain; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Objects; +import java.util.UUID; + +@Table(name = "order_table") +@Entity public class OrderTable { + @Column(name = "id", columnDefinition = "binary(16)") + @Id + private UUID id; + + private String name; + private int numberOfGuests; private boolean occupied; + public OrderTable(final String name, final int numberOfGuests, final boolean occupied) { + if (Objects.isNull(name) || name.isEmpty()) { + throw new IllegalArgumentException(); + } + this.name = name; + this.numberOfGuests = numberOfGuests; + this.occupied = occupied; + } + public OrderTable(final int numberOfGuests, final boolean occupied) { this.numberOfGuests = numberOfGuests; this.occupied = occupied; } + public OrderTable() { + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public int getNumberOfGuests() { + return numberOfGuests; + } + public boolean isOccupied() { return occupied; } @@ -17,4 +56,20 @@ public void makeEmpty() { numberOfGuests = 0; occupied = false; } + + public void setId(final UUID id) { + this.id = id; + } + + public void setName(final String name) { + this.name = name; + } + + public void setNumberOfGuests(final int numberOfGuests) { + this.numberOfGuests = numberOfGuests; + } + + public void setOccupied(final boolean occupied) { + this.occupied = occupied; + } } diff --git a/src/main/java/kitchenpos/eatinorders/ui/OrderRestController.java b/src/main/java/kitchenpos/eatinorders/ui/OrderRestController.java index 1c2741f73..d8e49e2a1 100644 --- a/src/main/java/kitchenpos/eatinorders/ui/OrderRestController.java +++ b/src/main/java/kitchenpos/eatinorders/ui/OrderRestController.java @@ -1,9 +1,15 @@ package kitchenpos.eatinorders.ui; import kitchenpos.eatinorders.application.OrderService; -import kitchenpos.eatinorders.domain.Order; +import kitchenpos.eatinorders.tobe.domain.Order; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.net.URI; import java.util.List; @@ -22,7 +28,7 @@ public OrderRestController(final OrderService orderService) { public ResponseEntity create(@RequestBody final Order request) { final Order response = orderService.create(request); return ResponseEntity.created(URI.create("/api/orders/" + response.getId())) - .body(response); + .body(response); } @PutMapping("/{orderId}/accept") diff --git a/src/main/java/kitchenpos/eatinorders/ui/OrderTableRestController.java b/src/main/java/kitchenpos/eatinorders/ui/OrderTableRestController.java index 120c28d1d..a8fe6a0de 100644 --- a/src/main/java/kitchenpos/eatinorders/ui/OrderTableRestController.java +++ b/src/main/java/kitchenpos/eatinorders/ui/OrderTableRestController.java @@ -1,7 +1,7 @@ package kitchenpos.eatinorders.ui; import kitchenpos.eatinorders.application.OrderTableService; -import kitchenpos.eatinorders.domain.OrderTable; +import kitchenpos.eatinorders.tobe.domain.OrderTable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; diff --git a/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderRepository.java b/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderRepository.java index 38d22969c..da87ccf07 100644 --- a/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderRepository.java +++ b/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderRepository.java @@ -1,11 +1,16 @@ package kitchenpos.eatinorders.application; -import kitchenpos.eatinorders.domain.Order; import kitchenpos.eatinorders.domain.OrderRepository; import kitchenpos.eatinorders.domain.OrderStatus; -import kitchenpos.eatinorders.domain.OrderTable; +import kitchenpos.eatinorders.tobe.domain.Order; +import kitchenpos.eatinorders.tobe.domain.OrderTable; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; public class InMemoryOrderRepository implements OrderRepository { private final Map orders = new HashMap<>(); @@ -29,7 +34,7 @@ public List findAll() { @Override public boolean existsByOrderTableAndStatusNot(final OrderTable orderTable, final OrderStatus status) { return orders.values() - .stream() - .anyMatch(order -> order.getOrderTable().equals(orderTable) && order.getStatus() != status); + .stream() + .anyMatch(order -> order.getOrderTable().equals(orderTable) && order.getStatus() != status); } } diff --git a/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderTableRepository.java b/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderTableRepository.java index 1aa4febce..67e144f24 100644 --- a/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderTableRepository.java +++ b/src/test/java/kitchenpos/eatinorders/application/InMemoryOrderTableRepository.java @@ -2,6 +2,7 @@ import kitchenpos.eatinorders.domain.OrderTable; import kitchenpos.eatinorders.domain.OrderTableRepository; +import kitchenpos.eatinorders.tobe.domain.OrderTable; import java.util.*; diff --git a/src/test/java/kitchenpos/eatinorders/application/OrderServiceTest.java b/src/test/java/kitchenpos/eatinorders/application/OrderServiceTest.java index 96bf0f286..ce1392a9e 100644 --- a/src/test/java/kitchenpos/eatinorders/application/OrderServiceTest.java +++ b/src/test/java/kitchenpos/eatinorders/application/OrderServiceTest.java @@ -1,18 +1,35 @@ package kitchenpos.eatinorders.application; -import kitchenpos.eatinorders.domain.*; +import kitchenpos.eatinorders.domain.OrderRepository; +import kitchenpos.eatinorders.domain.OrderStatus; +import kitchenpos.eatinorders.domain.OrderTableRepository; +import kitchenpos.eatinorders.domain.OrderType; +import kitchenpos.eatinorders.tobe.domain.Order; import kitchenpos.menus.application.InMemoryMenuRepository; import kitchenpos.menus.domain.MenuRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.*; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.NullSource; +import org.junit.jupiter.params.provider.ValueSource; import java.math.BigDecimal; -import java.util.*; - -import static kitchenpos.Fixtures.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import static kitchenpos.Fixtures.INVALID_ID; +import static kitchenpos.Fixtures.menu; +import static kitchenpos.Fixtures.menuProduct; +import static kitchenpos.Fixtures.order; +import static kitchenpos.Fixtures.orderTable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -39,17 +56,17 @@ void setUp() { void createDeliveryOrder() { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final Order expected = createOrderRequest( - OrderType.DELIVERY, "서울시 송파구 위례성대로 2", createOrderLineItemRequest(menuId, 19_000L, 3L) + OrderType.DELIVERY, "서울시 송파구 위례성대로 2", createOrderLineItemRequest(menuId, 19_000L, 3L) ); final Order actual = orderService.create(expected); assertThat(actual).isNotNull(); assertAll( - () -> assertThat(actual.getId()).isNotNull(), - () -> assertThat(actual.getType()).isEqualTo(expected.getType()), - () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.WAITING), - () -> assertThat(actual.getOrderDateTime()).isNotNull(), - () -> assertThat(actual.getOrderLineItems()).hasSize(1), - () -> assertThat(actual.getDeliveryAddress()).isEqualTo(expected.getDeliveryAddress()) + () -> assertThat(actual.getId()).isNotNull(), + () -> assertThat(actual.getType()).isEqualTo(expected.getType()), + () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.WAITING), + () -> assertThat(actual.getOrderDateTime()).isNotNull(), + () -> assertThat(actual.getOrderLineItems()).hasSize(1), + () -> assertThat(actual.getDeliveryAddress()).isEqualTo(expected.getDeliveryAddress()) ); } @@ -61,11 +78,11 @@ void createTakeoutOrder() { final Order actual = orderService.create(expected); assertThat(actual).isNotNull(); assertAll( - () -> assertThat(actual.getId()).isNotNull(), - () -> assertThat(actual.getType()).isEqualTo(expected.getType()), - () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.WAITING), - () -> assertThat(actual.getOrderDateTime()).isNotNull(), - () -> assertThat(actual.getOrderLineItems()).hasSize(1) + () -> assertThat(actual.getId()).isNotNull(), + () -> assertThat(actual.getType()).isEqualTo(expected.getType()), + () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.WAITING), + () -> assertThat(actual.getOrderDateTime()).isNotNull(), + () -> assertThat(actual.getOrderLineItems()).hasSize(1) ); } @@ -78,12 +95,12 @@ void createEatInOrder() { final Order actual = orderService.create(expected); assertThat(actual).isNotNull(); assertAll( - () -> assertThat(actual.getId()).isNotNull(), - () -> assertThat(actual.getType()).isEqualTo(expected.getType()), - () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.WAITING), - () -> assertThat(actual.getOrderDateTime()).isNotNull(), - () -> assertThat(actual.getOrderLineItems()).hasSize(1), - () -> assertThat(actual.getOrderTable().getId()).isEqualTo(expected.getOrderTableId()) + () -> assertThat(actual.getId()).isNotNull(), + () -> assertThat(actual.getType()).isEqualTo(expected.getType()), + () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.WAITING), + () -> assertThat(actual.getOrderDateTime()).isNotNull(), + () -> assertThat(actual.getOrderLineItems()).hasSize(1), + () -> assertThat(actual.getOrderTable().getId()).isEqualTo(expected.getOrderTableId()) ); } @@ -94,7 +111,7 @@ void create(final OrderType type) { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final Order expected = createOrderRequest(type, createOrderLineItemRequest(menuId, 19_000L, 3L)); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("메뉴가 없으면 등록할 수 없다.") @@ -103,14 +120,14 @@ void create(final OrderType type) { void create(final List orderLineItems) { final Order expected = createOrderRequest(OrderType.TAKEOUT, orderLineItems); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } private static List orderLineItems() { return Arrays.asList( - null, - Arguments.of(Collections.emptyList()), - Arguments.of(Arrays.asList(createOrderLineItemRequest(INVALID_ID, 19_000L, 3L))) + null, + Arguments.of(Collections.emptyList()), + Arguments.of(Arrays.asList(createOrderLineItemRequest(INVALID_ID, 19_000L, 3L))) ); } @@ -121,7 +138,7 @@ void createEatInOrder(final long quantity) { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final UUID orderTableId = orderTableRepository.save(orderTable(true, 4)).getId(); final Order expected = createOrderRequest( - OrderType.EAT_IN, orderTableId, createOrderLineItemRequest(menuId, 19_000L, quantity) + OrderType.EAT_IN, orderTableId, createOrderLineItemRequest(menuId, 19_000L, quantity) ); assertDoesNotThrow(() -> orderService.create(expected)); } @@ -132,10 +149,10 @@ OrderType.EAT_IN, orderTableId, createOrderLineItemRequest(menuId, 19_000L, quan void createWithoutEatInOrder(final long quantity) { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final Order expected = createOrderRequest( - OrderType.TAKEOUT, createOrderLineItemRequest(menuId, 19_000L, quantity) + OrderType.TAKEOUT, createOrderLineItemRequest(menuId, 19_000L, quantity) ); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("배달 주소가 올바르지 않으면 배달 주문을 등록할 수 없다.") @@ -144,10 +161,10 @@ OrderType.TAKEOUT, createOrderLineItemRequest(menuId, 19_000L, quantity) void create(final String deliveryAddress) { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final Order expected = createOrderRequest( - OrderType.DELIVERY, deliveryAddress, createOrderLineItemRequest(menuId, 19_000L, 3L) + OrderType.DELIVERY, deliveryAddress, createOrderLineItemRequest(menuId, 19_000L, 3L) ); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("빈 테이블에는 매장 주문을 등록할 수 없다.") @@ -156,10 +173,10 @@ void createEmptyTableEatInOrder() { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final UUID orderTableId = orderTableRepository.save(orderTable(false, 0)).getId(); final Order expected = createOrderRequest( - OrderType.EAT_IN, orderTableId, createOrderLineItemRequest(menuId, 19_000L, 3L) + OrderType.EAT_IN, orderTableId, createOrderLineItemRequest(menuId, 19_000L, 3L) ); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("숨겨진 메뉴는 주문할 수 없다.") @@ -168,7 +185,7 @@ void createNotDisplayedMenuOrder() { final UUID menuId = menuRepository.save(menu(19_000L, false, menuProduct())).getId(); final Order expected = createOrderRequest(OrderType.TAKEOUT, createOrderLineItemRequest(menuId, 19_000L, 3L)); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("주문한 메뉴의 가격은 실제 메뉴 가격과 일치해야 한다.") @@ -177,7 +194,7 @@ void createNotMatchedMenuPriceOrder() { final UUID menuId = menuRepository.save(menu(19_000L, true, menuProduct())).getId(); final Order expected = createOrderRequest(OrderType.TAKEOUT, createOrderLineItemRequest(menuId, 16_000L, 3L)); assertThatThrownBy(() -> orderService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("주문을 접수한다.") @@ -194,7 +211,7 @@ void accept() { void accept(final OrderStatus status) { final UUID orderId = orderRepository.save(order(status, orderTable(true, 4))).getId(); assertThatThrownBy(() -> orderService.accept(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("배달 주문을 접수되면 배달 대행사를 호출한다.") @@ -203,9 +220,9 @@ void acceptDeliveryOrder() { final UUID orderId = orderRepository.save(order(OrderStatus.WAITING, "서울시 송파구 위례성대로 2")).getId(); final Order actual = orderService.accept(orderId); assertAll( - () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.ACCEPTED), - () -> assertThat(kitchenridersClient.getOrderId()).isEqualTo(orderId), - () -> assertThat(kitchenridersClient.getDeliveryAddress()).isEqualTo("서울시 송파구 위례성대로 2") + () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.ACCEPTED), + () -> assertThat(kitchenridersClient.getOrderId()).isEqualTo(orderId), + () -> assertThat(kitchenridersClient.getDeliveryAddress()).isEqualTo("서울시 송파구 위례성대로 2") ); } @@ -223,7 +240,7 @@ void serve() { void serve(final OrderStatus status) { final UUID orderId = orderRepository.save(order(status)).getId(); assertThatThrownBy(() -> orderService.serve(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("주문을 배달한다.") @@ -239,7 +256,7 @@ void startDelivery() { void startDeliveryWithoutDeliveryOrder() { final UUID orderId = orderRepository.save(order(OrderStatus.SERVED)).getId(); assertThatThrownBy(() -> orderService.startDelivery(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("서빙된 주문만 배달할 수 있다.") @@ -248,7 +265,7 @@ void startDeliveryWithoutDeliveryOrder() { void startDelivery(final OrderStatus status) { final UUID orderId = orderRepository.save(order(status, "서울시 송파구 위례성대로 2")).getId(); assertThatThrownBy(() -> orderService.startDelivery(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("주문을 배달 완료한다.") @@ -265,7 +282,7 @@ void completeDelivery() { void completeDelivery(final OrderStatus status) { final UUID orderId = orderRepository.save(order(status, "서울시 송파구 위례성대로 2")).getId(); assertThatThrownBy(() -> orderService.completeDelivery(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("주문을 완료한다.") @@ -282,7 +299,7 @@ void complete() { void completeDeliveryOrder(final OrderStatus status) { final UUID orderId = orderRepository.save(order(status, "서울시 송파구 위례성대로 2")).getId(); assertThatThrownBy(() -> orderService.complete(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("포장 및 매장 주문의 경우 서빙된 주문만 완료할 수 있다.") @@ -291,7 +308,7 @@ void completeDeliveryOrder(final OrderStatus status) { void completeTakeoutAndEatInOrder(final OrderStatus status) { final UUID orderId = orderRepository.save(order(status)).getId(); assertThatThrownBy(() -> orderService.complete(orderId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("주문 테이블의 모든 매장 주문이 완료되면 빈 테이블로 설정한다.") @@ -301,9 +318,9 @@ void completeEatInOrder() { final Order expected = orderRepository.save(order(OrderStatus.SERVED, orderTable)); final Order actual = orderService.complete(expected.getId()); assertAll( - () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.COMPLETED), - () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().isOccupied()).isFalse(), - () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().getNumberOfGuests()).isEqualTo(0) + () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.COMPLETED), + () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().isOccupied()).isFalse(), + () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().getNumberOfGuests()).isEqualTo(0) ); } @@ -315,9 +332,9 @@ void completeNotTable() { final Order expected = orderRepository.save(order(OrderStatus.SERVED, orderTable)); final Order actual = orderService.complete(expected.getId()); assertAll( - () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.COMPLETED), - () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().isOccupied()).isTrue(), - () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().getNumberOfGuests()).isEqualTo(4) + () -> assertThat(actual.getStatus()).isEqualTo(OrderStatus.COMPLETED), + () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().isOccupied()).isTrue(), + () -> assertThat(orderTableRepository.findById(orderTable.getId()).get().getNumberOfGuests()).isEqualTo(4) ); } @@ -332,9 +349,9 @@ void findAll() { } private Order createOrderRequest( - final OrderType type, - final String deliveryAddress, - final OrderLineItem... orderLineItems + final OrderType type, + final String deliveryAddress, + final OrderLineItem... orderLineItems ) { final Order order = new Order(); order.setType(type); @@ -355,9 +372,9 @@ private Order createOrderRequest(final OrderType orderType, final List assertThat(actual.getId()).isNotNull(), - () -> assertThat(actual.getName()).isEqualTo(expected.getName()), - () -> assertThat(actual.getNumberOfGuests()).isZero(), - () -> assertThat(actual.isOccupied()).isFalse() + () -> assertThat(actual.getId()).isNotNull(), + () -> assertThat(actual.getName()).isEqualTo(expected.getName()), + () -> assertThat(actual.getNumberOfGuests()).isZero(), + () -> assertThat(actual.isOccupied()).isFalse() ); } @@ -52,7 +51,7 @@ void create() { void create(final String name) { final OrderTable expected = createOrderTableRequest(name); assertThatThrownBy(() -> orderTableService.create(expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("빈 테이블을 해지할 수 있다.") @@ -69,8 +68,8 @@ void clear() { final UUID orderTableId = orderTableRepository.save(orderTable(true, 4)).getId(); final OrderTable actual = orderTableService.clear(orderTableId); assertAll( - () -> assertThat(actual.getNumberOfGuests()).isZero(), - () -> assertThat(actual.isOccupied()).isFalse() + () -> assertThat(actual.getNumberOfGuests()).isZero(), + () -> assertThat(actual.isOccupied()).isFalse() ); } @@ -81,7 +80,7 @@ void clearWithUncompletedOrders() { final UUID orderTableId = orderTable.getId(); orderRepository.save(order(OrderStatus.ACCEPTED, orderTable)); assertThatThrownBy(() -> orderTableService.clear(orderTableId)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("방문한 손님 수를 변경할 수 있다.") @@ -100,7 +99,7 @@ void changeNumberOfGuests(final int numberOfGuests) { final UUID orderTableId = orderTableRepository.save(orderTable(true, 0)).getId(); final OrderTable expected = changeNumberOfGuestsRequest(numberOfGuests); assertThatThrownBy(() -> orderTableService.changeNumberOfGuests(orderTableId, expected)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @DisplayName("빈 테이블은 방문한 손님 수를 변경할 수 없다.") @@ -109,7 +108,7 @@ void changeNumberOfGuestsInEmptyTable() { final UUID orderTableId = orderTableRepository.save(orderTable(false, 0)).getId(); final OrderTable expected = changeNumberOfGuestsRequest(4); assertThatThrownBy(() -> orderTableService.changeNumberOfGuests(orderTableId, expected)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } @DisplayName("주문 테이블의 목록을 조회할 수 있다.") diff --git a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java index 16e501e45..916bb79d8 100644 --- a/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java +++ b/src/test/java/kitchenpos/eatinorders/tobe/domain/DeliveryOrderTest.java @@ -36,7 +36,7 @@ void register() { @Test void startDelivery() { final Order deliveryOrder = createDeliveryOrder(); - deliveryOrder.accept(new FakeKitchenridersClient(), BigDecimal.TEN); + deliveryOrder.accept(new FakeKitchenridersClient()); deliveryOrder.serve(); deliveryOrder.startDelivery(); @@ -47,7 +47,7 @@ void startDelivery() { @Test void completeDelivery() { final Order deliveryOrder = createDeliveryOrder(); - deliveryOrder.accept(new FakeKitchenridersClient(), BigDecimal.TEN); + deliveryOrder.accept(new FakeKitchenridersClient()); deliveryOrder.serve(); deliveryOrder.startDelivery();