-
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
112 changes: 112 additions & 0 deletions
112
src/main/java/kitchenpos/deliveryorders/application/DeliveryOrderService.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,112 @@ | ||
package kitchenpos.deliveryorders.application; | ||
|
||
import kitchenpos.deliveryorders.domain.DeliveryOrder; | ||
import kitchenpos.deliveryorders.domain.DeliveryOrderAddress; | ||
import kitchenpos.deliveryorders.domain.DeliveryOrderLineItem; | ||
import kitchenpos.deliveryorders.domain.DeliveryOrderLineItemPrice; | ||
import kitchenpos.deliveryorders.domain.DeliveryOrderLineItemQuantity; | ||
import kitchenpos.deliveryorders.domain.DeliveryOrderLineItems; | ||
import kitchenpos.deliveryorders.domain.DeliveryOrderRepository; | ||
import kitchenpos.deliveryorders.domain.KitchenridersClient; | ||
import kitchenpos.deliveryorders.domain.MenuClient; | ||
import kitchenpos.deliveryorders.shared.dto.DeliveryOrderLineItemDto; | ||
import kitchenpos.deliveryorders.shared.dto.DeliveryOrderDto; | ||
import kitchenpos.deliveryorders.shared.dto.request.DeliveryOrderCreateRequest; | ||
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 DeliveryOrderService { | ||
private DeliveryOrderRepository deliveryOrderRepository; | ||
private MenuClient menuClient; | ||
private KitchenridersClient kitchenridersClient; | ||
|
||
public DeliveryOrderService(DeliveryOrderRepository deliveryOrderRepository, MenuClient menuClient, KitchenridersClient kitchenridersClient) { | ||
this.deliveryOrderRepository = deliveryOrderRepository; | ||
this.menuClient = menuClient; | ||
this.kitchenridersClient = kitchenridersClient; | ||
} | ||
|
||
@Transactional | ||
public DeliveryOrderDto create(final DeliveryOrderCreateRequest request) { | ||
final List<DeliveryOrderLineItemDto> orderLineItemRequests = request.getOrderLineItems(); | ||
|
||
if (Objects.isNull(orderLineItemRequests) || orderLineItemRequests.isEmpty()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
List<DeliveryOrderLineItem> deliveryOrderLineItems = request.getOrderLineItems().stream() | ||
.map(deliveryOrderLineItemDto -> DeliveryOrderLineItem.of( | ||
deliveryOrderLineItemDto.getMenuId(), | ||
new DeliveryOrderLineItemQuantity(deliveryOrderLineItemDto.getQuantity()), | ||
new DeliveryOrderLineItemPrice(deliveryOrderLineItemDto.getPrice()), | ||
menuClient | ||
)) | ||
.collect(Collectors.toList()); | ||
|
||
DeliveryOrder deliveryOrder = DeliveryOrder.of( | ||
new DeliveryOrderLineItems(deliveryOrderLineItems), | ||
new DeliveryOrderAddress(request.getDeliveryAddress()), | ||
menuClient | ||
); | ||
|
||
return ConvertUtil.convert(deliveryOrderRepository.save(deliveryOrder), DeliveryOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public DeliveryOrderDto accept(final UUID orderId) { | ||
DeliveryOrder deliveryOrder = deliveryOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
deliveryOrder.accept(kitchenridersClient); | ||
|
||
return ConvertUtil.convert(deliveryOrder, DeliveryOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public DeliveryOrderDto serve(final UUID orderId) { | ||
DeliveryOrder deliveryOrder = deliveryOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
deliveryOrder.serve(); | ||
return ConvertUtil.convert(deliveryOrder, DeliveryOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public DeliveryOrderDto startDelivery(final UUID orderId) { | ||
DeliveryOrder deliveryOrder = deliveryOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
deliveryOrder.startDelivery(); | ||
return ConvertUtil.convert(deliveryOrder, DeliveryOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public DeliveryOrderDto completeDelivery(final UUID orderId) { | ||
DeliveryOrder deliveryOrder = deliveryOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
deliveryOrder.completeDelivery(); | ||
return ConvertUtil.convert(deliveryOrder, DeliveryOrderDto.class); | ||
} | ||
|
||
@Transactional | ||
public DeliveryOrderDto complete(final UUID orderId) { | ||
DeliveryOrder deliveryOrder = deliveryOrderRepository.findById(orderId) | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
deliveryOrder.complete(); | ||
return ConvertUtil.convert(deliveryOrder, DeliveryOrderDto.class); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<DeliveryOrderDto> findAll() { | ||
return ConvertUtil.convertList(deliveryOrderRepository.findAll(), DeliveryOrderDto.class); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
src/main/java/kitchenpos/deliveryorders/domain/DeliveryOrder.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,137 @@ | ||
package kitchenpos.deliveryorders.domain; | ||
|
||
import kitchenpos.eatinorders.domain.OrderStatus; | ||
import kitchenpos.eatinorders.domain.OrderType; | ||
import kitchenpos.menus.tobe.domain.menu.Menu; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Embedded; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
@Table(name = "delivery_orders") | ||
@Entity | ||
public class DeliveryOrder { | ||
@Column(name = "id", columnDefinition = "binary(16)") | ||
@Id | ||
private UUID id; | ||
|
||
@Column(name = "type", nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private OrderType type; | ||
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. 각각의 주문별로 바운디드 컨텍스트로 나누고 각각의 Table 도 분리해주신 것으로 보여져요. 😄 |
||
|
||
@Column(name = "status", nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private OrderStatus status; | ||
|
||
@Column(name = "order_date_time", nullable = false) | ||
private LocalDateTime orderDateTime; | ||
|
||
@Embedded | ||
private DeliveryOrderLineItems orderLineItems; | ||
|
||
@Embedded | ||
private DeliveryOrderAddress deliveryAddress; | ||
|
||
protected DeliveryOrder() { | ||
} | ||
|
||
public DeliveryOrder(UUID id, OrderType type, OrderStatus status, LocalDateTime orderDateTime, DeliveryOrderLineItems orderLineItems, DeliveryOrderAddress deliveryAddress) { | ||
this.id = id; | ||
this.type = type; | ||
this.status = status; | ||
this.orderDateTime = orderDateTime; | ||
this.orderLineItems = orderLineItems; | ||
this.deliveryAddress = deliveryAddress; | ||
} | ||
|
||
public static DeliveryOrder of(DeliveryOrderLineItems orderLineItems, DeliveryOrderAddress orderAddress, MenuClient menuClient) { | ||
validateDeliveryOrder(orderLineItems, menuClient); | ||
return new DeliveryOrder(UUID.randomUUID(), OrderType.DELIVERY, OrderStatus.WAITING, LocalDateTime.now(), orderLineItems, orderAddress); | ||
} | ||
|
||
private static void validateDeliveryOrder(DeliveryOrderLineItems orderLineItems, MenuClient menuClient) { | ||
List<Menu> menus = menuClient.findAllByIdIn( | ||
orderLineItems.getOrderLineItems().stream() | ||
.map(DeliveryOrderLineItem::getMenuId) | ||
.collect(Collectors.toList()) | ||
); | ||
if (menus.size() != orderLineItems.getOrderLineItems().size()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public OrderType getType() { | ||
return type; | ||
} | ||
|
||
public OrderStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public LocalDateTime getOrderDateTime() { | ||
return orderDateTime; | ||
} | ||
|
||
public List<DeliveryOrderLineItem> getOrderLineItems() { | ||
return orderLineItems.getOrderLineItems(); | ||
} | ||
|
||
public String getDeliveryAddress() { | ||
return deliveryAddress.getDeliveryOrderAddress(); | ||
} | ||
|
||
public void accept(KitchenridersClient kitchenridersClient) { | ||
if (status != OrderStatus.WAITING) { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
kitchenridersClient.requestDelivery(id, orderLineItems.getTotalDeliveryOrderLineItemsPrice(), getDeliveryAddress()); | ||
status = OrderStatus.ACCEPTED; | ||
} | ||
|
||
public void serve() { | ||
if (status != OrderStatus.ACCEPTED) { | ||
throw new IllegalStateException(); | ||
} | ||
this.status = OrderStatus.SERVED; | ||
} | ||
|
||
public void startDelivery() { | ||
if (type != OrderType.DELIVERY) { | ||
throw new IllegalStateException(); | ||
} | ||
if (status != OrderStatus.SERVED) { | ||
throw new IllegalStateException(); | ||
} | ||
status = OrderStatus.DELIVERING; | ||
} | ||
|
||
public void completeDelivery() { | ||
if (status != OrderStatus.DELIVERING) { | ||
throw new IllegalStateException(); | ||
} | ||
status = OrderStatus.DELIVERED; | ||
} | ||
|
||
public void complete() { | ||
if (type != OrderType.DELIVERY) { | ||
throw new IllegalStateException(); | ||
} | ||
if (status != OrderStatus.DELIVERED) { | ||
throw new IllegalStateException(); | ||
} | ||
status = OrderStatus.COMPLETED; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/kitchenpos/deliveryorders/domain/DeliveryOrderAddress.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,42 @@ | ||
package kitchenpos.deliveryorders.domain; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Embeddable; | ||
import java.util.Objects; | ||
|
||
@Embeddable | ||
public class DeliveryOrderAddress { | ||
@Column(name = "address", nullable = false) | ||
private String deliveryOrderAddress; | ||
|
||
protected DeliveryOrderAddress() { | ||
} | ||
|
||
public DeliveryOrderAddress(String deliveryOrderAddress) { | ||
validateDeliveryOrderAddress(deliveryOrderAddress); | ||
this.deliveryOrderAddress = deliveryOrderAddress; | ||
} | ||
|
||
private void validateDeliveryOrderAddress(String deliveryOrderAddress) { | ||
if (Objects.isNull(deliveryOrderAddress) || deliveryOrderAddress.isEmpty()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
public String getDeliveryOrderAddress() { | ||
return deliveryOrderAddress; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
DeliveryOrderAddress that = (DeliveryOrderAddress) o; | ||
return Objects.equals(deliveryOrderAddress, that.deliveryOrderAddress); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(deliveryOrderAddress); | ||
} | ||
} |
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.
지속적인 용어사전 업데이트 👍 👍
모델링도 구현하신 것에 맞게 업데이트도 해보면 어떨까요?