-
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 58 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,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,16 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public class CompletedOrderEvent { | ||
| private UUID orderTableId; | ||
|
|
||
| public CompletedOrderEvent(UUID orderTableId) { | ||
| this.orderTableId = orderTableId; | ||
| } | ||
|
|
||
| public UUID getOrderTableId() { | ||
| return orderTableId; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import kitchenpos.eatinorders.tobe.domain.constant.EatInOrderStatus; | ||
| import kitchenpos.eatinorders.tobe.domain.constant.EatInOrderType; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "orders2") | ||
| @Entity(name = "EatInOrder") | ||
| 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; | ||
|
|
||
| private UUID orderTableId; | ||
|
|
||
| protected EatInOrder() {} | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| 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() { | ||
| if (status != EatInOrderStatus.SERVED) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| status = EatInOrderStatus.COMPLETED; | ||
| } | ||
|
|
||
| public boolean isComplete() { | ||
| return status == EatInOrderStatus.COMPLETED; | ||
| } | ||
|
|
||
| public Set<UUID> allMenuId() { | ||
| return orderLineItems.allMenuId(); | ||
| } | ||
|
|
||
| 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,54 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "order_line_item2") | ||
| @Entity(name = "OrderLineItem2") | ||
| 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; | ||
|
|
||
| @Transient | ||
| private UUID menuId; | ||
|
||
|
|
||
| protected OrderLineItem() {} | ||
|
|
||
| public OrderLineItem(Long seq, long quantity, BigDecimal price) { | ||
| this(seq, quantity, price, null); | ||
| } | ||
|
||
|
|
||
| public OrderLineItem(Long seq, long quantity, BigDecimal price, UUID menuId) { | ||
| this.seq = seq; | ||
| this.quantity = quantity; | ||
| this.price = price; | ||
| this.menuId = menuId; | ||
| } | ||
|
|
||
| public Long getSeq() { | ||
| return seq; | ||
| } | ||
|
|
||
| public long getQuantity() { | ||
| return quantity; | ||
| } | ||
|
|
||
| public BigDecimal getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| public UUID getMenuId() { | ||
| return menuId; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @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 OrderLineItems(List<OrderLineItem> orderLineItems) { | ||
| this.orderLineItems = orderLineItems; | ||
| } | ||
|
|
||
| public Set<UUID> allMenuId() { | ||
| return orderLineItems.stream() | ||
| .map(orderLineItem -> orderLineItem.getMenuId()) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import kitchenpos.eatinorders.tobe.domain.vo.NumberOfGuests; | ||
| import kitchenpos.eatinorders.tobe.domain.vo.OrderTableName; | ||
| import kitchenpos.eatinorders.tobe.domain.constant.OrderTableStatus; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Table(name = "order_table2") | ||
| @Entity(name = "OrderTable2") | ||
| public class OrderTable { | ||
| @Column(name = "id", columnDefinition = "binary(16)") | ||
| @Id | ||
| private UUID id; | ||
|
|
||
| @Embedded | ||
| private OrderTableName name; | ||
|
|
||
| @Embedded | ||
| private NumberOfGuests numberOfGuests; | ||
|
|
||
| @Column(name = "occupied", nullable = false) | ||
| private boolean occupied; | ||
|
|
||
| @Transient | ||
| private OrderTableStatus status; | ||
|
|
||
|
||
| protected OrderTable() {} | ||
|
|
||
| public OrderTable(UUID id, String name, int numberOfGuests, boolean occupied) { | ||
| this.id = id; | ||
| this.name = new OrderTableName(name); | ||
| this.numberOfGuests = new NumberOfGuests(numberOfGuests); | ||
| this.occupied = occupied; | ||
| status = OrderTableStatus.EMPTY_TABLE; | ||
| checkNumberAtInitialize(numberOfGuests); | ||
| } | ||
|
|
||
| private void checkNumberAtInitialize(int numberOfGuests) { | ||
| if (status == OrderTableStatus.EMPTY_TABLE && numberOfGuests != 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| public void sit() { | ||
| occupied = true; | ||
| status = OrderTableStatus.SIT_TABLE; | ||
| } | ||
|
|
||
| public void clear() { | ||
| numberOfGuests = NumberOfGuests.zero(); | ||
| occupied = false; | ||
| status = OrderTableStatus.EMPTY_TABLE; | ||
| } | ||
|
|
||
| public void changeNumberOfGuests(int numberOfGuests) { | ||
| NumberOfGuests inputNumberOfGuests = new NumberOfGuests(numberOfGuests); | ||
| if (status != OrderTableStatus.SIT_TABLE) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| this.numberOfGuests = inputNumberOfGuests; | ||
| } | ||
|
|
||
| public boolean isNotOccupied() { | ||
| return !occupied; | ||
| } | ||
|
|
||
| public boolean isOccupied() { | ||
| return occupied; | ||
| } | ||
|
|
||
| public UUID getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public int getNumberOfGuests() { | ||
| return numberOfGuests.getNumberOfGuests(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.repository; | ||
|
|
||
| import kitchenpos.eatinorders.tobe.domain.entity.EatInOrder; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| public interface EatInOrderRepository { | ||
|
|
||
| EatInOrder save(EatInOrder order); | ||
|
|
||
| Optional<EatInOrder> findById(UUID id); | ||
|
|
||
| List<EatInOrder> findAllByOrderTableId(UUID id); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||
| package kitchenpos.eatinorders.tobe.domain.repository; | ||||||||||||||
|
|
||||||||||||||
| import kitchenpos.eatinorders.tobe.domain.entity.OrderTable; | ||||||||||||||
| import java.util.Optional; | ||||||||||||||
| import java.util.UUID; | ||||||||||||||
|
|
||||||||||||||
| public interface OrderTableRepository { | ||||||||||||||
|
|
||||||||||||||
| OrderTable save(OrderTable orderTable); | ||||||||||||||
|
|
||||||||||||||
| Optional<OrderTable> findBy(UUID id); | ||||||||||||||
| } | ||||||||||||||
|
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.
Suggested change
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package kitchenpos.eatinorders.tobe.domain.service; | ||
|
|
||
| import kitchenpos.eatinorders.tobe.domain.entity.EatInOrder; | ||
| import kitchenpos.eatinorders.tobe.domain.entity.OrderTable; | ||
| 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.Set; | ||
| import java.util.UUID; | ||
|
|
||
| public class EatInOrderAccept { | ||
| private OrderTableRepository tableRepository; | ||
|
Comment on lines
+12
to
+14
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. 이 클래스는 EatInOrder를 생성하는 시점에 사용될 것 같아요.
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. bean으로 등록되지 않아도 괜찮나요?
Author
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. MenuInEatInOrders 생성 시점도 EatInOrders와 동일한 생성 시점으로 생각하고 있습니다. MenuInEatInOrders에 대한 유효성을 검증하기 위해서는 EatInOrder 객체가 생성되어 하기에 EatInOrderTest 클래스에서 유효성 검증 테스트 코드 작성했습니다. |
||
| private MenuRepository menuRepository; | ||
|
|
||
| public EatInOrderAccept(OrderTableRepository tableRepository, MenuRepository menuRepository) { | ||
| this.tableRepository = tableRepository; | ||
| this.menuRepository = menuRepository; | ||
| } | ||
|
|
||
| public void checkRequiredList(EatInOrder order) { | ||
| checkOrderTableIsOccupied(order.getOrderTableId()); | ||
| checkAllMenuIsDisplayed(order.allMenuId()); | ||
| } | ||
|
|
||
| private void checkOrderTableIsOccupied(UUID orderId) { | ||
| OrderTable table = tableRepository.findBy(orderId) | ||
| .orElseThrow(() -> new NoSuchElementException()); | ||
|
|
||
| if (table.isNotOccupied()) { | ||
| throw new IllegalStateException("빈 테이블입니다."); | ||
| } | ||
| } | ||
|
|
||
| private void checkAllMenuIsDisplayed(Set<UUID> allMenuId) { | ||
| boolean hasNotDisplayedMenu = allMenuId.stream() | ||
| .anyMatch(menuId -> isNotDisplayedMenu(menuId)); | ||
|
|
||
| if (hasNotDisplayedMenu) { | ||
| throw new IllegalStateException("숨긴 메뉴가 존재합니다."); | ||
| } | ||
| } | ||
|
|
||
| private boolean isNotDisplayedMenu(UUID menuId) { | ||
| Menu menu = menuRepository.findById(menuId) | ||
| .orElseThrow(() -> new NoSuchElementException()); | ||
| return menu.isNotDisplayed(); | ||
| } | ||
| } | ||
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.
#271 (comment)