-
Notifications
You must be signed in to change notification settings - Fork 177
3단계 - 리팩터링(매장 식사 주문) #242
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
Open
seungjoopet
wants to merge
4
commits into
next-step:seungjoopet
Choose a base branch
from
seungjoopet:step3
base: seungjoopet
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
3단계 - 리팩터링(매장 식사 주문) #242
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
src/main/java/kitchenpos/eatinorders/adapter/eatinorder/out/JpaEatinOrderRepository.java
This file contains hidden or 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,11 @@ | ||
| package kitchenpos.eatinorders.adapter.eatinorder.out; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.out.EatinOrderRepository; | ||
| import kitchenpos.eatinorders.domain.eatinorder.EatinOrder; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface JpaEatinOrderRepository extends EatinOrderRepository, | ||
| JpaRepository<EatinOrder, UUID> { | ||
|
|
||
| } | ||
26 changes: 26 additions & 0 deletions
26
src/main/java/kitchenpos/eatinorders/adapter/eatinorder/out/ValidMenuAdapter.java
This file contains hidden or 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,26 @@ | ||
| package kitchenpos.eatinorders.adapter.eatinorder.out; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.out.ValidMenuPort; | ||
| import kitchenpos.menu.application.menu.port.in.MenuFindUseCase; | ||
|
|
||
| public class ValidMenuAdapter implements ValidMenuPort { | ||
|
|
||
| private final MenuFindUseCase menuFindUseCase; | ||
|
|
||
| public ValidMenuAdapter(final MenuFindUseCase menuFindUseCase) { | ||
| this.menuFindUseCase = menuFindUseCase; | ||
| } | ||
|
|
||
| @Override | ||
| public void checkValidMenu(final List<UUID> menuIds) { | ||
| if (menuIds.size() != menuFindUseCase.findAll() | ||
| .stream() | ||
| .filter(menu -> menuIds.contains(menu.getId())) | ||
| .count()) { | ||
|
|
||
| throw new IllegalStateException(String.format("menu is not exist. ids: %s", menuIds)); | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/kitchenpos/eatinorders/adapter/ordertable/out/JpaOrderTableRepository.java
This file contains hidden or 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,11 @@ | ||
| package kitchenpos.eatinorders.adapter.ordertable.out; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.application.ordertable.port.out.OrderTableNewRepository; | ||
| import kitchenpos.eatinorders.domain.ordertable.OrderTableNew; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface JpaOrderTableRepository extends OrderTableNewRepository, | ||
| JpaRepository<OrderTableNew, UUID> { | ||
|
|
||
| } |
68 changes: 68 additions & 0 deletions
68
src/main/java/kitchenpos/eatinorders/application/eatinorder/DefaultEatinOrderService.java
This file contains hidden or 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,68 @@ | ||
| package kitchenpos.eatinorders.application.eatinorder; | ||
|
|
||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.in.EatinOrderDTO; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.in.EatinOrderInitCommand; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.in.EatinOrderUseCase; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.out.EatinOrderRepository; | ||
| import kitchenpos.eatinorders.application.eatinorder.port.out.ValidMenuPort; | ||
| import kitchenpos.eatinorders.application.exception.NotExistEatinOrderException; | ||
| import kitchenpos.eatinorders.application.ordertable.port.out.OrderTableNewRepository; | ||
| import kitchenpos.eatinorders.domain.eatinorder.EatinOrder; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| public class DefaultEatinOrderService implements EatinOrderUseCase { | ||
|
|
||
| private final EatinOrderRepository eatinOrderRepository; | ||
| private final OrderTableNewRepository orderTableRepository; | ||
| private final ValidMenuPort menuFindPort; | ||
|
|
||
| public DefaultEatinOrderService(final EatinOrderRepository eatinOrderRepository, | ||
| final OrderTableNewRepository orderTableRepository, final ValidMenuPort menuFindPort) { | ||
|
|
||
| this.eatinOrderRepository = eatinOrderRepository; | ||
| this.orderTableRepository = orderTableRepository; | ||
| this.menuFindPort = menuFindPort; | ||
| } | ||
|
|
||
| @Override | ||
| public EatinOrderDTO init(final EatinOrderInitCommand command) { | ||
|
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. 등록에 대해서 용어 사전에 정리하신 것은 없지만 init이라는 이름은 모호한 것 같은데 적당한 것으로 바꿔볼 수 있을까요? |
||
| final EatinOrder eatinOrder = eatinOrderRepository.save( | ||
| EatinOrder.create(command.getOrderTableId(), | ||
| command.getOrderLineItemMenuIds(), | ||
| command.getOrderLineItemCommands() | ||
| .stream() | ||
| .map(item -> Pair.of(item.getMenuId(), item.getQuantity())) | ||
| .collect(Collectors.toUnmodifiableList()), | ||
| orderTableRepository, menuFindPort)); | ||
|
|
||
| return new EatinOrderDTO(eatinOrder); | ||
| } | ||
|
|
||
| @Override | ||
| public void accept(final UUID id) { | ||
| final EatinOrder order = eatinOrderRepository.findById(id) | ||
| .orElseThrow(() -> new NotExistEatinOrderException(id)); | ||
|
|
||
| order.acceptOrder(); | ||
| } | ||
|
|
||
| @Override | ||
| public void serve(final UUID id) { | ||
| final EatinOrder order = eatinOrderRepository.findById(id) | ||
| .orElseThrow(() -> new NotExistEatinOrderException(id)); | ||
|
|
||
| order.serveOrder(); | ||
| } | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void complete(final UUID id) { | ||
| final EatinOrder order = eatinOrderRepository.findById(id) | ||
| .orElseThrow(() -> new NotExistEatinOrderException(id)); | ||
|
|
||
| order.completeOrder(orderTableRepository); | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/main/java/kitchenpos/eatinorders/application/eatinorder/port/in/EatinOrderDTO.java
This file contains hidden or 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,22 @@ | ||
| package kitchenpos.eatinorders.application.eatinorder.port.in; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
| import kitchenpos.eatinorders.domain.eatinorder.EatinOrder; | ||
|
|
||
| public final class EatinOrderDTO { | ||
|
|
||
| private final UUID id; | ||
| private final List<OrderLineItemDTO> orderLineItems; | ||
| private final UUID orderTableId; | ||
|
|
||
| public EatinOrderDTO(final EatinOrder order) { | ||
| this.id = order.getId(); | ||
| this.orderLineItems = order.getOrderLineItems() | ||
| .stream() | ||
| .map(OrderLineItemDTO::new) | ||
| .collect(Collectors.toUnmodifiableList()); | ||
| this.orderTableId = order.getOrderTableId(); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
...ain/java/kitchenpos/eatinorders/application/eatinorder/port/in/EatinOrderInitCommand.java
This file contains hidden or 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,51 @@ | ||
| package kitchenpos.eatinorders.application.eatinorder.port.in; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public final class EatinOrderInitCommand { | ||
|
|
||
| private final UUID orderTableId; | ||
| private final List<OrderLineItemCommand> orderLineItemCommands; | ||
|
|
||
| public EatinOrderInitCommand(final UUID orderTableId, | ||
| final List<OrderLineItemCommand> orderLineItemCommands) { | ||
|
|
||
| this.orderTableId = orderTableId; | ||
| this.orderLineItemCommands = orderLineItemCommands; | ||
| } | ||
|
|
||
| public UUID getOrderTableId() { | ||
| return orderTableId; | ||
| } | ||
|
|
||
| public List<OrderLineItemCommand> getOrderLineItemCommands() { | ||
| return orderLineItemCommands; | ||
| } | ||
|
|
||
| public List<UUID> getOrderLineItemMenuIds() { | ||
| return orderLineItemCommands.stream() | ||
| .map(OrderLineItemCommand::getMenuId) | ||
| .collect(Collectors.toUnmodifiableList()); | ||
| } | ||
|
|
||
| public static final class OrderLineItemCommand { | ||
|
|
||
| private final UUID menuId; | ||
| private final int quantity; | ||
|
|
||
| public OrderLineItemCommand(final UUID menuId, final int quantity) { | ||
| this.menuId = menuId; | ||
| this.quantity = quantity; | ||
| } | ||
|
|
||
| public UUID getMenuId() { | ||
| return menuId; | ||
| } | ||
|
|
||
| public int getQuantity() { | ||
| return quantity; | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/main/java/kitchenpos/eatinorders/application/eatinorder/port/in/EatinOrderUseCase.java
This file contains hidden or 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.eatinorders.application.eatinorder.port.in; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.application.exception.InvalidAcceptStatusException; | ||
| import kitchenpos.eatinorders.application.exception.InvalidCompleteStatusException; | ||
| import kitchenpos.eatinorders.application.exception.InvalidServeStatusException; | ||
| import kitchenpos.eatinorders.application.exception.NotExistOrderTableException; | ||
|
|
||
| public interface EatinOrderUseCase { | ||
|
|
||
| /** | ||
| * @throws NotExistOrderTableException orderTableId에 해당하는 table이 없을 때 | ||
| * @throws IllegalStateException orderLineItem에 있는 menu가 없는 menu일 때 | ||
| */ | ||
| EatinOrderDTO init(final EatinOrderInitCommand command); | ||
|
|
||
| /** | ||
| * @throws NotExistOrderTableException orderTableId에 해당하는 table이 없을 때 | ||
| * @throws InvalidAcceptStatusException accept를 할 수 없는 상태일 때 | ||
| */ | ||
| void accept(final UUID id); | ||
|
|
||
| /** | ||
| * @throws NotExistOrderTableException orderTableId에 해당하는 table이 없을 때 | ||
| * @throws InvalidServeStatusException serve를 할 수 없는 상태일 때 | ||
| */ | ||
| void serve(final UUID id); | ||
|
|
||
| /** | ||
| * @throws NotExistOrderTableException orderTableId에 해당하는 table이 없을 때 | ||
| * @throws InvalidCompleteStatusException complete를 할 수 없는 상태일 때 | ||
| */ | ||
| void complete(final UUID id); | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/kitchenpos/eatinorders/application/eatinorder/port/in/OrderLineItemDTO.java
This file contains hidden or 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,17 @@ | ||
| package kitchenpos.eatinorders.application.eatinorder.port.in; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.domain.eatinorder.OrderLineItemNew; | ||
|
|
||
| public final class OrderLineItemDTO { | ||
|
|
||
| private final UUID id; | ||
| private final UUID menuId; | ||
| private final int quantity; | ||
|
|
||
| public OrderLineItemDTO(final OrderLineItemNew orderLineItem) { | ||
| this.id = orderLineItem.getId(); | ||
| this.menuId = orderLineItem.getMenuId(); | ||
| this.quantity = orderLineItem.getQuantity(); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...ain/java/kitchenpos/eatinorders/application/eatinorder/port/out/EatinOrderRepository.java
This file contains hidden or 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,12 @@ | ||
| package kitchenpos.eatinorders.application.eatinorder.port.out; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.domain.eatinorder.EatinOrder; | ||
|
|
||
| public interface EatinOrderRepository { | ||
|
|
||
| EatinOrder save(final EatinOrder eatinOrder); | ||
|
|
||
| Optional<EatinOrder> findById(final UUID id); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/kitchenpos/eatinorders/application/eatinorder/port/out/ValidMenuPort.java
This file contains hidden or 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,12 @@ | ||
| package kitchenpos.eatinorders.application.eatinorder.port.out; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public interface ValidMenuPort { | ||
|
|
||
| /** | ||
| * @throws IllegalStateException orderLineItem에 있는 menu가 없는 menu일 때 | ||
| */ | ||
| void checkValidMenu(final List<UUID> menuIds); | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/kitchenpos/eatinorders/application/exception/InvalidAcceptStatusException.java
This file contains hidden or 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,11 @@ | ||
| package kitchenpos.eatinorders.application.exception; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.domain.eatinorder.Status; | ||
|
|
||
| public class InvalidAcceptStatusException extends InvalidEatinOrderStatusException { | ||
|
|
||
| public InvalidAcceptStatusException(final UUID id, final Status currentStatus) { | ||
| super(id, currentStatus); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...ain/java/kitchenpos/eatinorders/application/exception/InvalidCompleteStatusException.java
This file contains hidden or 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,11 @@ | ||
| package kitchenpos.eatinorders.application.exception; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.domain.eatinorder.Status; | ||
|
|
||
| public class InvalidCompleteStatusException extends InvalidEatinOrderStatusException { | ||
|
|
||
| public InvalidCompleteStatusException(final UUID id, final Status currentStatus) { | ||
| super(id, currentStatus); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...n/java/kitchenpos/eatinorders/application/exception/InvalidEatinOrderStatusException.java
This file contains hidden or 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,12 @@ | ||
| package kitchenpos.eatinorders.application.exception; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.domain.eatinorder.Status; | ||
|
|
||
| public class InvalidEatinOrderStatusException extends RuntimeException { | ||
|
|
||
| public InvalidEatinOrderStatusException(final UUID id, final Status currentStatus) { | ||
| super(String.format("invalid eatin order status. id: %s, currentStatus: %s", id, | ||
| currentStatus)); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/kitchenpos/eatinorders/application/exception/InvalidServeStatusException.java
This file contains hidden or 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,11 @@ | ||
| package kitchenpos.eatinorders.application.exception; | ||
|
|
||
| import java.util.UUID; | ||
| import kitchenpos.eatinorders.domain.eatinorder.Status; | ||
|
|
||
| public class InvalidServeStatusException extends InvalidEatinOrderStatusException { | ||
|
|
||
| public InvalidServeStatusException(final UUID id, final Status currentStatus) { | ||
| super(id, currentStatus); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/kitchenpos/eatinorders/application/exception/NotExistEatinOrderException.java
This file contains hidden or 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,22 @@ | ||
| package kitchenpos.eatinorders.application.exception; | ||
|
|
||
| import com.google.common.base.MoreObjects; | ||
| import java.util.UUID; | ||
|
|
||
| public final class NotExistEatinOrderException extends RuntimeException { | ||
|
|
||
| private final UUID id; | ||
|
|
||
| public NotExistEatinOrderException(final UUID id) { | ||
| super(String.format("not exist order. id: %s", id)); | ||
|
|
||
| this.id = id; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return MoreObjects.toStringHelper(this) | ||
| .add("id", id) | ||
| .toString(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
이번엔 시간 관계상 전체적으로 TC를 제외하셨군요 😄