-
Notifications
You must be signed in to change notification settings - Fork 177
3단계 - 리팩터링(매장 식사 주문) #289
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
base: pawoo0211
Are you sure you want to change the base?
3단계 - 리팩터링(매장 식사 주문) #289
Changes from 31 commits
b7c9083
c43e274
f2260de
ab73347
623bad4
6fd402e
abd44e0
eafef3d
a95b239
7a34cd0
b0e7f58
03009d2
993630b
fdf5132
940bbc0
6a3bc8c
34f17f8
f718f35
b7d6076
bb80df0
af38e43
443acc1
5cd6899
6f1d289
ce1c3af
6d21ef3
5107e75
49830eb
9b09de2
3f16f60
c3a161d
45d26b8
860bdcb
e983561
558e2a7
eccbe2b
07ff076
a80da1b
9962450
b796d70
21b8f13
babffa7
6986496
5e1603f
f256d6a
715b933
cd012ad
fc1c97a
8568977
fce2e2e
cf50ce9
eeb4fce
a4257d5
fe08dd9
ea91181
e732a74
5e84dc8
3286a41
bd53968
9cd603f
2a3a17c
19c576d
22d0891
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package kitchenpos.eatinorders.tobe.application.acl; | ||
|
|
||
| import kitchenpos.eatinorders.tobe.domain.entity.EatInOrder; | ||
| import kitchenpos.eatinorders.tobe.domain.entity.OrderTable; | ||
| import kitchenpos.eatinorders.tobe.domain.repository.EatInOrderRepository; | ||
| import kitchenpos.eatinorders.tobe.domain.repository.OrderTableRepository; | ||
| import kitchenpos.menus.tobe.domain.entity.Menu; | ||
| import kitchenpos.menus.tobe.domain.repository.MenuRepository; | ||
|
|
||
| import java.util.NoSuchElementException; | ||
| import java.util.UUID; | ||
|
|
||
| public class EatInOrderServiceAdapter { | ||
| private final EatInOrderRepository orderRepository; | ||
| private final OrderTableRepository orderTableRepository; | ||
| private final MenuRepository menuRepository; | ||
|
|
||
| public EatInOrderServiceAdapter(EatInOrderRepository orderRepository, | ||
| OrderTableRepository orderTableRepository, | ||
| MenuRepository menuRepository | ||
| ) { | ||
| this.orderRepository = orderRepository; | ||
| this.orderTableRepository = orderTableRepository; | ||
| this.menuRepository = menuRepository; | ||
| } | ||
|
|
||
| public boolean existHideMenu(UUID menuId) { | ||
| Menu menu = findMenuById(menuId); | ||
| if (menu.isNotDisplayed()) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private Menu findMenuById(UUID menuId) { | ||
| return menuRepository.findById(menuId) | ||
| .orElseThrow(() -> new NoSuchElementException()); | ||
| } | ||
|
|
||
| public boolean existIsNotOccupiedOrderTable(EatInOrder order) { | ||
| OrderTable orderTable = findOrderTableBy(order.getOrderTableId()); | ||
| return orderTable.isNotOccupied(); | ||
| } | ||
|
|
||
| public void clearOrderTable(EatInOrder order) { | ||
| OrderTable orderTable = findOrderTableBy(order.getOrderTableId()); | ||
| if (orderRepository.isAllCompleteByOrderTable(orderTable)) { | ||
| orderTable.clear(); | ||
| } | ||
| } | ||
|
|
||
| private OrderTable findOrderTableBy(UUID id) { | ||
| return orderTableRepository.findBy(id) | ||
| .orElseThrow(() -> new NoSuchElementException()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.constant; | ||
|
|
||
| public enum EatInOrderStatus { | ||
| WAITING, ACCEPTED, SERVED, COMPLETED | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.constant; | ||
|
|
||
| public enum EatInOrderType { | ||
| EAT_IN | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.constant; | ||
|
|
||
| public enum OrderTableStatus { | ||
| EMPTY_TABLE, | ||
| SIT_TABLE | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import kitchenpos.eatinorders.tobe.domain.constant.EatInOrderStatus; | ||
| import kitchenpos.eatinorders.tobe.domain.constant.EatInOrderType; | ||
| import kitchenpos.eatinorders.tobe.application.acl.EatInOrderServiceAdapter; | ||
|
|
||
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "orders") | ||
| @Entity | ||
| public class EatInOrder { | ||
|
||
| @Column(name = "id", columnDefinition = "binary(16)") | ||
| @Id | ||
| private UUID id; | ||
|
|
||
| @Column(name = "type", nullable = false, columnDefinition = "varchar(255)") | ||
| @Enumerated(EnumType.STRING) | ||
| private EatInOrderType type; | ||
|
|
||
| @Column(name = "status", nullable = false, columnDefinition = "varchar(255)") | ||
| @Enumerated(EnumType.STRING) | ||
| private EatInOrderStatus status; | ||
|
|
||
| @Column(name = "order_date_time", nullable = false) | ||
| private LocalDateTime orderDateTime; | ||
|
|
||
| @Embedded | ||
| private OrderLineItems orderLineItems; | ||
|
|
||
| @Transient | ||
| private UUID orderTableId; | ||
|
|
||
| public EatInOrder(UUID id, EatInOrderType type, EatInOrderStatus status, LocalDateTime orderDateTime, | ||
| OrderLineItems orderLineItems, UUID orderTableId, | ||
| EatInOrderServiceAdapter orderDomainService) { | ||
| this(id, type, status, orderDateTime, orderLineItems, orderTableId); | ||
| checkOrderTableOccupied(orderDomainService); | ||
| checkAllMenuIsDisplayed(orderDomainService); | ||
| } | ||
|
|
||
| public EatInOrder(UUID id, EatInOrderType type, EatInOrderStatus status, LocalDateTime orderDateTime, | ||
| OrderLineItems orderLineItems, UUID orderTableId) { | ||
| this.id = id; | ||
| this.type = type; | ||
| this.status = status; | ||
| this.orderDateTime = orderDateTime; | ||
| this.orderLineItems = orderLineItems; | ||
| this.orderTableId = orderTableId; | ||
| } | ||
|
|
||
| private void checkAllMenuIsDisplayed(EatInOrderServiceAdapter orderDomainService) { | ||
| if (orderLineItems.hasDisplayedMenu(orderDomainService)) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| } | ||
|
|
||
| private void checkOrderTableOccupied(EatInOrderServiceAdapter orderDomainService) { | ||
| if (orderDomainService.existIsNotOccupiedOrderTable(this)) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| } | ||
|
|
||
| public void accept() { | ||
| if (status != EatInOrderStatus.WAITING) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| status = EatInOrderStatus.ACCEPTED; | ||
| } | ||
|
|
||
| public void serve() { | ||
| if (status != EatInOrderStatus.ACCEPTED) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| status = EatInOrderStatus.SERVED; | ||
| } | ||
|
|
||
| public void complete(EatInOrderServiceAdapter eatInOrderServiceAdapter) { | ||
| if (status != EatInOrderStatus.SERVED) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| status = EatInOrderStatus.COMPLETED; | ||
| eatInOrderServiceAdapter.clearOrderTable(this); | ||
| } | ||
|
||
|
|
||
| public UUID getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public EatInOrderType getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public EatInOrderStatus getStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| public UUID getOrderTableId() { | ||
| return orderTableId; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||||||||||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.*; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Column(name = "quantity", nullable = false) | ||||||||||||||||||||||||||||||||||||||||||
| private long quantity; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Transient | ||||||||||||||||||||||||||||||||||||||||||
| private BigDecimal price; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||
| @Transient | ||||||||||||||||||||||||||||||||||||||||||
| private UUID menuId; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| protected OrderLineItem() {} | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| public OrderLineItem(Long seq, long quantity, BigDecimal price, UUID menuId) { | ||||||||||||||||||||||||||||||||||||||||||
| this(seq, quantity, price); | ||||||||||||||||||||||||||||||||||||||||||
| this.menuId = menuId; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| public OrderLineItem(Long seq, long quantity, BigDecimal price) { | ||||||||||||||||||||||||||||||||||||||||||
| this.seq = seq; | ||||||||||||||||||||||||||||||||||||||||||
| this.quantity = quantity; | ||||||||||||||||||||||||||||||||||||||||||
| this.price = price; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| public OrderLineItem(Long seq, long quantity, BigDecimal price, UUID menuId) { | |
| this(seq, quantity, price); | |
| this.menuId = menuId; | |
| } | |
| public OrderLineItem(Long seq, long quantity, BigDecimal price) { | |
| this.seq = seq; | |
| this.quantity = quantity; | |
| this.price = price; | |
| } | |
| public OrderLineItem(Long seq, long quantity, BigDecimal price, UUID menuId) { | |
| this.seq = seq; | |
| this.quantity = quantity; | |
| this.price = price; | |
| this.menuId = menuId; | |
| } | |
| public OrderLineItem(Long seq, long quantity, BigDecimal price) { | |
| this(seq, quantity, price, null); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import kitchenpos.eatinorders.tobe.application.acl.EatInOrderServiceAdapter; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Embeddable | ||
| public class OrderLineItems { | ||
| @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<OrderLineItem> orderLineItems; | ||
|
|
||
| protected OrderLineItems() {} | ||
|
|
||
| public boolean hasDisplayedMenu(EatInOrderServiceAdapter orderDomainService) { | ||
| return orderLineItems.stream() | ||
| .map(orderLineItem -> orderLineItem.getMenuId()) | ||
| .anyMatch(menuId -> orderDomainService.existHideMenu(menuId)); | ||
| } | ||
|
||
|
|
||
| public OrderLineItems(List<OrderLineItem> orderLineItems) { | ||
| this.orderLineItems = orderLineItems; | ||
| } | ||
| } | ||
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.
orderRepository 에서는 orderTable를 직접 의존하고 있네요. 이 부분도 id 변경해야 하지 않을까요?