Skip to content

Commit

Permalink
feat: add product palletized event to client orders bc
Browse files Browse the repository at this point in the history
  • Loading branch information
vitlinda authored and nicolasfara committed Aug 11, 2022
1 parent 24897a3 commit 4b8474c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import cats.syntax.all.*

import dev.atedeg.mdm.clientorders.InProgressOrderLine.*
import dev.atedeg.mdm.clientorders.OrderCompletionError.*
import dev.atedeg.mdm.clientorders.OutgoingEvent.OrderProcessed
import dev.atedeg.mdm.clientorders.OutgoingEvent.{ OrderProcessed, ProductPalletized }
import dev.atedeg.mdm.clientorders.PalletizationError.*
import dev.atedeg.mdm.clientorders.utils.*
import dev.atedeg.mdm.clientorders.utils.QuantityOps.*
Expand Down Expand Up @@ -60,7 +60,10 @@ def startPreparingOrder(pricedOrder: PricedOrder): InProgressOrder =
* where the corresponding [[Order.InProgressOrderLine line]] has been updated with the
* [[Order.Quantity specified quantity]].
*/
def palletizeProductForOrder[M[_]: CanRaise[PalletizationError]: Monad](quantity: Quantity, product: Product)(
def palletizeProductForOrder[M[_]: CanRaise[PalletizationError]: Monad: Emits[ProductPalletized]](
quantity: Quantity,
product: Product,
)(
inProgressOrder: InProgressOrder,
): M[InProgressOrder] =
val InProgressOrder(id, ol, customer, dd, dl, totalPrice) = inProgressOrder
Expand All @@ -71,6 +74,7 @@ def palletizeProductForOrder[M[_]: CanRaise[PalletizationError]: Monad](quantity
case Incomplete(_, _, `product`, _) => updatedLine
case l @ _ => l
}
_ <- emit(ProductPalletized(product, quantity): ProductPalletized)
yield InProgressOrder(id, newOrderLines, customer, dd, dl, totalPrice)

private def hasProduct(product: Product)(ol: InProgressOrderLine): Boolean = ol match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ enum OutgoingEvent:
* An event emitted when a new [[IncomingOrder incoming order]] is received and processed.
*/
case OrderProcessed(incomingOrder: IncomingOrder)

/**
* An event emitted when a [[Product product]] is successfully palletized for an [[Order.InProgressoOrder order]].
*/
case ProductPalletized(product: Product, quantity: Quantity)
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ final case class IncomingOrderDTO(
object OrderProcessedDTO:
given DTO[OrderProcessed, OrderProcessedDTO] = interCaseClassDTO
private given DTO[IncomingOrder, IncomingOrderDTO] = interCaseClassDTO

final case class ProductPalletizedDTO(product: ProductDTO, quantity: Int)
object ProductPalletizedDTO:
given DTO[ProductPalletized, ProductPalletizedDTO] = interCaseClassDTO
private given DTO[Quantity, Int] = caseClassDTO

0 comments on commit 4b8474c

Please sign in to comment.