Skip to content
Open
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b7c9083
test: 주 생성자 사용 로직으로 수정
pawoo0211 May 23, 2024
c43e274
test: 테스트 코드를 위한 메서드 제거
pawoo0211 May 23, 2024
f2260de
test: 이름, 가격 도메인 테스트 코드 작성
pawoo0211 May 23, 2024
ab73347
refactor: To Be 메뉴 그룹 구현
pawoo0211 May 23, 2024
623bad4
refactor: To Be 메뉴 상품 구현
pawoo0211 May 27, 2024
6fd402e
refactor: To Be 메뉴 구현
pawoo0211 May 27, 2024
abd44e0
refactor: DisplayedName -> CleanName으로 네이밍 변경
pawoo0211 May 28, 2024
eafef3d
refactor: DisplayedName 제거
pawoo0211 May 28, 2024
a95b239
refactor: 메뉴 숨김 getter 로직 제거
pawoo0211 May 28, 2024
7a34cd0
test: 랜덤 객체 재사용으로 수정
pawoo0211 May 29, 2024
b0e7f58
test: 상품 생성 메서드 제거
pawoo0211 May 29, 2024
03009d2
test: 메뉴 도메인 이름 테스트 코드 추가
pawoo0211 May 29, 2024
993630b
refactor: 메뉴 -> 메뉴 그룹 id 의존으로 변경
pawoo0211 May 29, 2024
fdf5132
refactor: 메뉴 상품 -> 상품 id 의존 변경에 따른 1차 리팩터링
pawoo0211 May 29, 2024
940bbc0
refactor: 메뉴 상품 -> 상품 id 의존 변경에 따른 2차 리팩터링
pawoo0211 May 29, 2024
6a3bc8c
refactor: 메뉴 상품 -> 상품 객체 의존 제거
pawoo0211 May 29, 2024
34f17f8
chore: 메뉴 상품 리팩터링 테스트 코드 정리
pawoo0211 May 29, 2024
f718f35
refactor: 메뉴 상품 가격 반환 리팩터링
pawoo0211 May 31, 2024
b7d6076
refactor: 메뉴 상품 가격과 메뉴 가격 비교 메서드 위치 및 네이밍 변경
pawoo0211 May 31, 2024
bb80df0
test: 가격 도메인 추가 테스트 코드 작성
pawoo0211 May 31, 2024
af38e43
refactor: 두번째 미션 마지막 피드백 적용
pawoo0211 Jun 1, 2024
443acc1
feat: To Be 주문 테이블 구현
pawoo0211 Jun 1, 2024
5cd6899
feat: To Be 주문 항목 뼈대 코드 작성
pawoo0211 Jun 1, 2024
6f1d289
feat: To Be 주문 뼈대 코드 작성
pawoo0211 Jun 1, 2024
ce1c3af
refactor: To Be 패키지 구조 변경
pawoo0211 Jun 1, 2024
6d21ef3
refactor: 주문 등록 전 빈 테이블 확인 및 주문 완료 후 빈 테이블 설정 구현
pawoo0211 Jun 1, 2024
5107e75
refactor: 주문 ACL 클래스에 따른 패키지 구조 변경
pawoo0211 Jun 1, 2024
49830eb
refactor: 주문 ACL 클래스에 따른 메뉴 패키지 구조 변경
pawoo0211 Jun 1, 2024
9b09de2
feat: 주문 생성 시 메뉴 검증 구현
pawoo0211 Jun 1, 2024
3f16f60
test: 테스트 전 저장해야 하는 데이터 셋 코드 정리
pawoo0211 Jun 1, 2024
c3a161d
Merge branch 'pawoo0211' into step3
pawoo0211 Jun 1, 2024
45d26b8
refactor: 주문 완료에 따른 빈 테이블 설정 로직 리팩터링
pawoo0211 Jun 5, 2024
860bdcb
test: 스프링 통합 테스트를 위한 임시 엔티티 네이밍 수정
pawoo0211 Jun 5, 2024
e983561
refactor: 주문 완료에 따른 빈 설정 이벤트 기반으로 리팩터링
pawoo0211 Jun 5, 2024
558e2a7
refactor: 주문 생성 시 검증 로직 리팩터링
pawoo0211 Jun 5, 2024
eccbe2b
test: 생성자를 이용한 주문 상태 변경
pawoo0211 Jun 5, 2024
07ff076
test: 테스트 코드를 위한 메서드 제거
pawoo0211 May 23, 2024
a80da1b
test: 이름, 가격 도메인 테스트 코드 작성
pawoo0211 May 23, 2024
9962450
refactor: To Be 메뉴 그룹 구현
pawoo0211 May 23, 2024
b796d70
refactor: To Be 메뉴 상품 구현
pawoo0211 May 27, 2024
21b8f13
refactor: To Be 메뉴 구현
pawoo0211 May 27, 2024
babffa7
refactor: DisplayedName -> CleanName으로 네이밍 변경
pawoo0211 May 28, 2024
6986496
refactor: DisplayedName 제거
pawoo0211 May 28, 2024
5e1603f
refactor: 메뉴 숨김 getter 로직 제거
pawoo0211 May 28, 2024
f256d6a
test: 랜덤 객체 재사용으로 수정
pawoo0211 May 29, 2024
715b933
test: 상품 생성 메서드 제거
pawoo0211 May 29, 2024
cd012ad
test: 메뉴 도메인 이름 테스트 코드 추가
pawoo0211 May 29, 2024
fc1c97a
refactor: 메뉴 -> 메뉴 그룹 id 의존으로 변경
pawoo0211 May 29, 2024
8568977
refactor: 메뉴 상품 -> 상품 id 의존 변경에 따른 1차 리팩터링
pawoo0211 May 29, 2024
fce2e2e
refactor: 메뉴 상품 -> 상품 id 의존 변경에 따른 2차 리팩터링
pawoo0211 May 29, 2024
cf50ce9
refactor: 메뉴 상품 -> 상품 객체 의존 제거
pawoo0211 May 29, 2024
eeb4fce
chore: 메뉴 상품 리팩터링 테스트 코드 정리
pawoo0211 May 29, 2024
a4257d5
refactor: 메뉴 상품 가격 반환 리팩터링
pawoo0211 May 31, 2024
fe08dd9
refactor: 메뉴 상품 가격과 메뉴 가격 비교 메서드 위치 및 네이밍 변경
pawoo0211 May 31, 2024
ea91181
test: 가격 도메인 추가 테스트 코드 작성
pawoo0211 May 31, 2024
e732a74
Merge remote-tracking branch 'origin/step3' into step3
pawoo0211 Jun 6, 2024
5e84dc8
fix: 머지 충돌 해결
pawoo0211 Jun 6, 2024
3286a41
fix: 누락된 커밋 추가
pawoo0211 Jun 6, 2024
bd53968
fix: 주문 항목 메뉴 식별자 및 금액 예외 처리
pawoo0211 Jun 7, 2024
9cd603f
fix: 주문 항목 금액과 메뉴 금액 일치 여부에ㄷ 따른 수정
pawoo0211 Jun 7, 2024
2a3a17c
refactor: 메뉴 변경에 따른 주문 검증
pawoo0211 Jun 7, 2024
19c576d
refactor: 동일한 사용에 따라 OrderTableStatus 제거
pawoo0211 Jun 7, 2024
22d0891
chore: 이벤트 핸들링 시 로깅 처리
pawoo0211 Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Transient
private UUID menuId;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고민해 볼만한 포인트인 것 같습니다. menu는 id로 참조하고 있는데요.
그렇다면 보통 주문한 시점의 menu가 필요합니다. (스냅샷) 하지만 간접 참조로 인해서 주문한 시점의 정보를 불러 오기 힘들 것 같은데요. 이 부분은 어떻게 해결할 수 있을까요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우 메뉴 MC 에서 menu name이 변경되는 경우 어떻게 처리 될까요?

얼마 전에 저희 DM 으로 Menu BC에서의 menu와 Order BC에서 Menu는 의미하는 바가 다름을 도출했는데요. 이를 코드로 녹여보는 것은 어떨까요? Order에 Menu 모델이 만들어 질 수도 있지 않을까요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

price와 menuId는 Transient 로 선언되어도 괜찮나요?


protected OrderLineItem() {}

public OrderLineItem(Long seq, long quantity, BigDecimal price) {
this(seq, quantity, price, null);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 생성자를 둬 클라이언트에게 편의를 주는 것은 좋은데요. menu는 없어도 괜찮나요?


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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

occupied 와 status 모두 필요할까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

논리적으로 동일하네요 하하..

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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Optional<OrderTable> findBy(UUID id);
}
Optional<OrderTable> findById(UUID id);
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 클래스는 EatInOrder를 생성하는 시점에 사용될 것 같아요.

MenuInEatInOrders의 생성 시점은 언제인가요? 🤔

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bean으로 등록되지 않아도 괜찮나요?

Copy link
Author

Choose a reason for hiding this comment

The 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();
}
}
Loading