Lab 6 - TDD Application Service - Expose Kitchen Business Interface and Implement Transactions
1. Summary
In DDD, we use an Application Service to expose operations involving Aggregates and Repositories, or multiple Aggregates. An Application Service is the first immediate client of the core Domain Model.
We would eventually use the interface of an Application Service to expose its operations as a REST API or message-driven collaboration using RabbitMQ or Kafka.
In this lab, we’ll build out the ApplicationService for the Kitchen context.
We will complete 10 stories:
-
The ability to find a
KitchenOrderby itsOnlineOrderRef. -
When an
OnlineOrderPaidEventis published by the Ordering context, create aKitchenOrder. -
The ability to start prep on a
KitchenOrder. -
When a
KitchenOrderPrepStartedEventis published, create aPizzafor everyKitchenOrder.Pizza, and then start prep on eachPizza. -
The ability to finish prep on a
Pizza. -
When a
PizzaPrepFinishedEventis published, start baking the pizza. -
When a
PizzaBakeStartedEventis published, start baking the order. -
The ability to remove a pizza from the oven.
-
When the first pizza in an order has finished baking (i.e.
PizzaBakeFinishedEvent), start assembling the order. -
When the final pizza in an order has finished baking, finish assembling the order.
You can run com.mattstine.dddworkshop.pizzashop.suites.Lab6Suite to check your progress in this lab.
2. Instructions
-
Implement the following command methods:
-
startOrderPrep() -
finishPizzaPrep() -
removePizzaFromOven()
-
-
Implement the following finders:
-
findKitchenOrderByRef() -
findKitchenOrderByOnlineOrderRef() -
findPizzaByRef() -
findPizzasByKitchenOrderRef()
-
-
Subscribe to the
orderingtopic. On anOnlineOrderPaidEvent, retrieve the asssociatedOnlineOrderby itsRef. Convert theOnlineOrderto aKitchenOrder, and add it to the repository. -
Subscribe to the
ktichen_orderstopic. On aKitchenOrderPrepStartedEvent, create aPizzafor eachKitchenOrder.Pizza, and add it to the repository. ThenstartPrep()on thePizza. -
Subscribe to the
pizzastopic:-
On a
PizzaPrepFinishedEvent, retrieve the associatedPizzaandstartBake(). -
On a
PizzaBakeStartedEvent, retrieve the associatedKitchenOrder. If theKitchenOrderis prepping,startBake(). -
On a
PizzaBakeFinishedEvent, retrieve the associatedKitchenOrder. If theKitchenOrderis baking,startAssembly(). Next, retrieve all of the associatedPizzainstances. If all of them have finished baking,finishAssemblyon theKitchenOrder.
-