-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2단계 - 리팩터링(메뉴) #169
Open
chr0m3
wants to merge
35
commits into
next-step:chr0m3
Choose a base branch
from
chr0m3:step2
base: chr0m3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
2단계 - 리팩터링(메뉴) #169
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
bde7ea3
Price에 multiply() 추가
chr0m3 86b5760
MenuGroup entity 추가
chr0m3 4022276
MenuGroupEntity 추가
chr0m3 8382a9b
MenuGroupEntityConverter 추가
chr0m3 a1644b4
MenuGroupRepository 추가
chr0m3 b84cfe6
JpaMenuGroupRepository, JpaMenuGroupDao 추가
chr0m3 eb121a6
Price.multiply() 테스트 추가
chr0m3 4e44a8f
Price에 add() 추가
chr0m3 2c52931
Price가 Comparable을 구현하도록 수정
chr0m3 0146904
MenuProductQuantity VO 추가
chr0m3 a968bc6
MenuProduct VO 추가
chr0m3 7ff9973
MenuGroup VO 추가
chr0m3 3621adb
Menu entity 추가
chr0m3 5aab011
MenuDisplayPolicy 추가
chr0m3 58bd527
MenuRepository 추가
chr0m3 0701e17
Menu의 isVisible을 displayed로 변경
chr0m3 bf9bfb1
MenuEntity 추가
chr0m3 44adb96
MenuGroup VO 삭제
chr0m3 2d16e74
MenuProductEntity 추가
chr0m3 218f580
MenuProductEntityConverter 추가
chr0m3 c346395
누락된 final 추가
chr0m3 26aa5e7
MenuEntityConverter 추가
chr0m3 ac684f6
JpaMenuRepository 추가
chr0m3 748ee71
JpaMenuRepository 리팩터링 - 중복 코드 제거
chr0m3 96fe49a
메뉴 노출 정책을 위반하는 가격 변경이 불가능하도록 수정
chr0m3 f795b5c
새로운 도메인 모델을 사용하도록 Menu 컨텍스트 수정
chr0m3 2c7035e
불필요해진 과거 코드 제거
chr0m3 a662282
CreateMenuGroupCommand DTO 추가
chr0m3 a753755
ChangeMenuPriceCommand DTO 추가
chr0m3 86dc9e6
CreateMenuCommand DTO 추가
chr0m3 81afbbc
메뉴 노출 정책을 위반하는 메뉴 생성이 불가능하도록 수정
chr0m3 bd08ccb
메뉴 생성시 정확한 상품 가격을 반영하도록 개선
chr0m3 71f200a
DB 마이그레이션
chr0m3 139c6f8
도메인 모델 수정
chr0m3 1c460a0
Converter 인터페이스 제거
chr0m3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/kitchenpos/menu/tobe/domain/vo/MenuProduct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kitchenpos.menu.tobe.domain.vo; | ||
|
||
import java.util.UUID; | ||
import kitchenpos.common.price.Price; | ||
|
||
public class MenuProduct { | ||
|
||
public final UUID productId; | ||
|
||
public final Price pricePerUnit; | ||
|
||
public final MenuProductQuantity quantity; | ||
|
||
public MenuProduct( | ||
final UUID productId, | ||
final Price pricePerUnit, | ||
final MenuProductQuantity quantity | ||
) { | ||
this.productId = productId; | ||
this.pricePerUnit = pricePerUnit; | ||
this.quantity = quantity; | ||
} | ||
|
||
public Price subtotal() { | ||
return this.pricePerUnit.multiply(this.quantity.value); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
MenuProduct that = (MenuProduct) o; | ||
|
||
if (!productId.equals(that.productId)) { | ||
return false; | ||
} | ||
if (!pricePerUnit.equals(that.pricePerUnit)) { | ||
return false; | ||
} | ||
return quantity.equals(that.quantity); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = productId.hashCode(); | ||
result = 31 * result + pricePerUnit.hashCode(); | ||
result = 31 * result + quantity.hashCode(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package kitchenpos.menu; | ||
|
||
import java.util.Random; | ||
import java.util.UUID; | ||
import kitchenpos.common.name.NameFactory; | ||
import kitchenpos.common.price.Price; | ||
import kitchenpos.common.profanity.FakeProfanityDetectService; | ||
import kitchenpos.common.profanity.domain.ProfanityDetectService; | ||
import kitchenpos.menu.tobe.domain.entity.MenuGroup; | ||
import kitchenpos.menu.tobe.domain.vo.MenuProduct; | ||
import kitchenpos.menu.tobe.domain.vo.MenuProductQuantity; | ||
import kitchenpos.product.tobe.domain.entity.Product; | ||
|
||
public class Fixtures { | ||
|
||
private static final ProfanityDetectService profanityDetectService = new FakeProfanityDetectService(); | ||
|
||
private static final NameFactory nameFactory = new NameFactory(profanityDetectService); | ||
|
||
public static MenuGroup menuGroup() { | ||
return menuGroup("두마리메뉴"); | ||
} | ||
|
||
public static MenuGroup menuGroup(final String name) { | ||
return new MenuGroup(UUID.randomUUID(), nameFactory.create(name)); | ||
} | ||
|
||
public static MenuProduct menuProduct() { | ||
return new MenuProduct( | ||
UUID.randomUUID(), | ||
new Price(10_000), | ||
new MenuProductQuantity(new Random().nextInt(10)) | ||
); | ||
} | ||
|
||
public static MenuProduct menuProduct(final Product product, final long quantity) { | ||
return new MenuProduct( | ||
UUID.randomUUID(), | ||
product.price(), | ||
new MenuProductQuantity(quantity) | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/kitchenpos/menu/tobe/domain/vo/MenuProductTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package kitchenpos.menu.tobe.domain.vo; | ||
|
||
import static kitchenpos.menu.Fixtures.menuProduct; | ||
import static kitchenpos.product.Fixtures.product; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import kitchenpos.common.price.Price; | ||
import kitchenpos.product.tobe.domain.entity.Product; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class MenuProductTest { | ||
|
||
@DisplayName("subtotal()") | ||
@Nested | ||
class Cvxueewc { | ||
|
||
@DisplayName("소계가 올바르게 계산되어야 한다.") | ||
@ValueSource(longs = { | ||
16, 8, 32, 4, 1, | ||
15, 13, 3, 31, 18, | ||
}) | ||
@ParameterizedTest | ||
void czxovwxu(final long quantity) { | ||
final long pricePerUnit = 10000; | ||
final Product product = product("상품", pricePerUnit); | ||
final MenuProduct menuProduct = menuProduct(product, quantity); | ||
|
||
assertThat(menuProduct.subtotal()).isEqualTo(new Price(pricePerUnit * quantity)); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단순히
price
를 사용하는 경우 메뉴 하나의 가격인지, 메뉴 가격에 수량을 곱한 소계에 해당하는 값인지 혼동되어 명확하게 네이밍했습니다.