-
Notifications
You must be signed in to change notification settings - Fork 153
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
step3 (매장 식사 주문) #246
Open
yuhwanwoo
wants to merge
7
commits into
next-step:yuhwanwoo
Choose a base branch
from
yuhwanwoo:step3
base: yuhwanwoo
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
step3 (매장 식사 주문) #246
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aa31b61
feature(order): step2 리뷰 반영(menuProductPrice 영속화)
hwanwooyu ce277ce
feature(order): 배달 주문 작성
yuhwanwoo 267e943
feature(order): 배달 주문 작성
yuhwanwoo a888d59
feature(order): 매장 주문 작성
yuhwanwoo f4da63b
feature(refactoring): order Type 제거
hwanwooyu 33e3f30
feature(refactoring): order 완료시 상태 조건 변경
hwanwooyu b21163d
feature(refactoring): 모델링 업데이트
hwanwooyu 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 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
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
105 changes: 105 additions & 0 deletions
105
src/main/java/kitchenpos/eatinorders/application/EatInOrderService.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,105 @@ | ||
package kitchenpos.eatinorders.application; | ||
|
||
import kitchenpos.eatinorders.tobe.domain.order.EatInMenuClient; | ||
import kitchenpos.eatinorders.domain.OrderStatus; | ||
import kitchenpos.eatinorders.shared.dto.EatInOrderDto; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrderLineItems; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrderRepository; | ||
import kitchenpos.eatinorders.tobe.domain.ordertable.OrderTable; | ||
import kitchenpos.eatinorders.tobe.domain.ordertable.OrderTableRepository; | ||
import kitchenpos.eatinorders.shared.dto.EatInOrderLineItemDto; | ||
import kitchenpos.eatinorders.shared.dto.request.EatInOrderCreateRequest; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrder; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrderLineItem; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrderLineItemPrice; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrderLineItemQuantity; | ||
import kitchenpos.menus.tobe.domain.menu.MenuRepository; | ||
import kitchenpos.shared.util.ConvertUtil; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class EatInOrderService { | ||
private final EatInOrderRepository eatInOrderRepository; | ||
private final MenuRepository menuRepository; | ||
private final OrderTableRepository orderTableRepository; | ||
private final EatInMenuClient eatInMenuClient; | ||
|
||
public EatInOrderService(EatInOrderRepository eatInOrderRepository, MenuRepository menuRepository, OrderTableRepository orderTableRepository, EatInMenuClient eatInMenuClient) { | ||
this.eatInOrderRepository = eatInOrderRepository; | ||
this.menuRepository = menuRepository; | ||
this.orderTableRepository = orderTableRepository; | ||
this.eatInMenuClient = eatInMenuClient; | ||
} | ||
|
||
@Transactional | ||
public EatInOrderDto create(final EatInOrderCreateRequest request) { | ||
List<EatInOrderLineItemDto> orderLineItemRequests = request.getOrderLineItems(); | ||
if (Objects.isNull(orderLineItemRequests) || orderLineItemRequests.isEmpty()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
List<EatInOrderLineItem> orderLineItems = request.getOrderLineItems().stream() | ||
.map(eatInOrderLineItemDto -> EatInOrderLineItem.of( | ||
eatInOrderLineItemDto.getMenuId(), | ||
new EatInOrderLineItemQuantity(eatInOrderLineItemDto.getQuantity()), | ||
new EatInOrderLineItemPrice(eatInOrderLineItemDto.getPrice()), | ||
eatInMenuClient | ||
)) | ||
.collect(Collectors.toList()); | ||
|
||
OrderTable orderTable = orderTableRepository.findById(request.getOrderTableId()) | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
EatInOrder eatInOrder = EatInOrder.of( | ||
new EatInOrderLineItems(orderLineItems), | ||
orderTable, | ||
eatInMenuClient | ||
); | ||
|
||
return ConvertUtil.convert(eatInOrderRepository.save(eatInOrder), EatInOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public EatInOrderDto accept(UUID orderId) { | ||
EatInOrder eatInOrder = eatInOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
eatInOrder.accept(); | ||
return ConvertUtil.convert(eatInOrder, EatInOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public EatInOrderDto serve(UUID orderId) { | ||
EatInOrder eatInOrder = eatInOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
eatInOrder.serve(); | ||
return ConvertUtil.convert(eatInOrder, EatInOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public EatInOrderDto complete(UUID orderId) { | ||
EatInOrder eatInOrder = eatInOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
eatInOrder.complete(); | ||
|
||
OrderTable orderTable = orderTableRepository.findById(eatInOrder.getOrderTable().getId()) | ||
.orElseThrow(NoSuchElementException::new); | ||
if (!eatInOrderRepository.existsByOrderTableAndStatusNot(orderTable, OrderStatus.COMPLETED)) { | ||
orderTable.clear(); | ||
} | ||
return ConvertUtil.convert(eatInOrder, EatInOrderDto.class); | ||
} | ||
|
||
|
||
@Transactional | ||
public List<EatInOrderDto> findAll() { | ||
return ConvertUtil.convertList(eatInOrderRepository.findAll(), EatInOrderDto.class); | ||
} | ||
|
||
} |
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
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
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
2 changes: 2 additions & 0 deletions
2
src/main/java/kitchenpos/eatinorders/domain/OrderRepository.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
59 changes: 0 additions & 59 deletions
59
src/main/java/kitchenpos/eatinorders/domain/OrderTable.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/main/java/kitchenpos/eatinorders/infra/EatInMenuClientImpl.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,30 @@ | ||
package kitchenpos.eatinorders.infra; | ||
|
||
import kitchenpos.eatinorders.tobe.domain.order.EatInMenuClient; | ||
import kitchenpos.menus.tobe.domain.menu.Menu; | ||
import kitchenpos.menus.tobe.domain.menu.MenuRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Service | ||
public class EatInMenuClientImpl implements EatInMenuClient { | ||
|
||
private final MenuRepository menuRepository; | ||
|
||
public EatInMenuClientImpl(MenuRepository menuRepository) { | ||
this.menuRepository = menuRepository; | ||
} | ||
|
||
@Override | ||
public Optional<Menu> findById(UUID id) { | ||
return menuRepository.findById(id); | ||
} | ||
|
||
@Override | ||
public List<Menu> findAllByIdIn(List<UUID> ids) { | ||
return menuRepository.findAllByIdIn(ids); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/kitchenpos/eatinorders/infra/JpaEatInOrderRepositoryImpl.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,11 @@ | ||
package kitchenpos.eatinorders.infra; | ||
|
||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrder; | ||
import kitchenpos.eatinorders.tobe.domain.order.EatInOrderRepository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface JpaEatInOrderRepositoryImpl extends EatInOrderRepository, JpaRepository<EatInOrder, UUID> { | ||
|
||
} |
4 changes: 3 additions & 1 deletion
4
...rders/domain/JpaOrderTableRepository.java → ...orders/infra/JpaOrderTableRepository.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
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.
매장주문이 완료되었을 때 도메인 로직이 어떻게 수행되어야한다고 생각하실까요? 🤔
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.
전 주문 상태 Served로 수정했습니다! 🙇
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.
말씀드리고 싶었던 것은 현재 로직 중에 도메인로직으로 보이는 부분이 있어서 도메인 계층으로 위임하면 어떨까 의견을 드려본 것이였어요 😄
주문완료하는 로직에서 주문테이블과 매장주문 애그리거트간의 협력도 필요하다고 봐요.
그렇기 때문에 도메인 계층으로 위임할 때 여러 고민도 해보시면 좋을 것 같아서요
모델링 해주신 것을 봤을 때는 지금처럼 구현한 것도 좋지만, 응용계층에서 도메인에 대한 제어가 더 많아질 것 같아요
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.
말씀해주신 부분을 생각해보았는데요!
제 생각에는 사진 처럼
public void complete(EatInOrderRepository eatInOrderRepository)
메소드에 EatInOrderRepository를 파라미터로 받아야할 것 같은데 제가 이해한 게 맞을까요...?
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.
스크린샷에 올려주신 코드가 매장 주문 도메인인가요? 🤔
도메인에 레포지토리를 주입하거나 파라미터로 넘겨주는 행위는 저는 지양하고 있어요
루트 애그리거트의 핵심역할이 애그리거트의 일관성이 개지지 않다록 하는 것인데 레포지토리를 주입받거나 파라미터로 넘겨주게되면
타 애그리거트의 일관성이 깨질 우려가 있어요
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.
네 매장주문 도메인인데요!
말씀해주신 방향으로 고민을 해봤는데, 도메인 로직으로 옮기려면
이런식으로 작성해야 하지 않나해서 repository에 대해 질문드렸었습니다!
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.
그리고 제가 현재 고민하고 있던 부분도 이에 대한 것중 하나인데
구현하는 로직중 운영정책 등록 시 제목이 없다면 해당 정책의 Category명 + 숫자(숫자는 등록 시 마다 증가)
라는 요구사항이 존재하는데요. 해당 부분을 구현하기 위해서 고민을 해본 결과
Terms의 정적 메소드에 termsRepository 를 파라미터로 받도록 할 수 밖에 없을 것 같은데
말씀하신 방향대로라면 어떻게 진행하는 것이 맞는 방향인걸까요...?