Skip to content

Commit

Permalink
feat: add endpoints to complete orders and get their transport document
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri authored and vitlinda committed Aug 11, 2022
1 parent 9cae769 commit 27973fe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def orderCompletedHandler[M[_]: Monad: LiftIO: CanRaise[String]: CanRead[Configu
_ <- config.orderRepository.updateOrderToCompleted(completedOrder.toDTO)
yield ()

def getDDTHandler[M[_]: Monad: LiftIO: CanRaise[String]: CanRead[Configuration]](orderID: String): M[Unit] =
def getTransportDocumentHandler[M[_]: Monad: LiftIO: CanRaise[String]: CanRead[Configuration]](
orderID: String,
): M[TransportDocumentDTO] =
(readState >>= (_.orderRepository.readCompletedOrder(orderID)) >>= validate)
.map(o => createTransportDocument(o, weightOrder(o)))
.map(o => createTransportDocument(o, weightOrder(o)).toDTO)
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object OrdersEndpoint:
val newOrderEndpoint: PublicEndpoint[OrderReceivedDTO, String, String, Any] =
endpoint.post
.in("order")
.in(jsonBody[OrderReceivedDTO].description("TODO"))
.out(stringBody)
.in(jsonBody[OrderReceivedDTO].description("The order that needs to be placed"))
.out(stringBody.description("The ID assigned to the placed order"))
.errorOut(stringBody)

val newOrderRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
Expand All @@ -33,7 +33,7 @@ object OrdersEndpoint:
val palletizeProductForOrder: PublicEndpoint[ProductPalletizedForOrderDTO, String, Unit, Any] =
endpoint.post
.in("order" / "palletize")
.in(jsonBody[ProductPalletizedForOrderDTO].description("TODO"))
.in(jsonBody[ProductPalletizedForOrderDTO].description("The product and quantity palletized for the given order"))
.errorOut(stringBody)

val palletizeProductRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
Expand All @@ -42,3 +42,33 @@ object OrdersEndpoint:
action.value.run(Configuration(PriceListRepositoryDB("foo"), OrderRepositoryDB("bar"), EmitterMQ()))
},
)

@SuppressWarnings(Array("org.wartremover.warts.Any"))
val orderCompletedEndpoint: PublicEndpoint[OrderCompletedDTO, String, Unit, Any] =
endpoint.post
.in("order" / "complete")
.in(jsonBody[OrderCompletedDTO].description("The ID of the order that has been completed"))
.errorOut(stringBody)

val orderCompletedRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
orderCompletedEndpoint.serverLogic { o =>
val action: ServerAction[Configuration, String, Unit] = orderCompletedHandler(o)
action.value.run(Configuration(PriceListRepositoryDB("foo"), OrderRepositoryDB("bar"), EmitterMQ()))
},
)

@SuppressWarnings(Array("org.wartremover.warts.Any"))
val getTransportDocumentEndpoint: PublicEndpoint[String, String, TransportDocumentDTO, Any] =
endpoint.get
.in("order")
.in(path[String].description("The ID of the order for which the transport document is requested"))
.in("ddt")
.out(jsonBody[TransportDocumentDTO].description("The transport document for the given order"))
.errorOut(stringBody)

val getTransportDocumentRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
getTransportDocumentEndpoint.serverLogic { o =>
val action: ServerAction[Configuration, String, TransportDocumentDTO] = getTransportDocumentHandler(o)
action.value.run(Configuration(PriceListRepositoryDB("foo"), OrderRepositoryDB("bar"), EmitterMQ()))
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,16 @@ final case class CompletedOrderLineDTO(quantity: Int, product: ProductDTO, price
object CompletedOrderDTO:
given DTO[CompletedOrder, CompletedOrderDTO] = interCaseClassDTO
private given DTO[CompleteOrderLine, CompletedOrderLineDTO] = interCaseClassDTO

final case class TransportDocumentDTO(
deliveryLocation: LocationDTO,
shippingLocation: LocationDTO,
customer: CustomerDTO,
shippingDate: String,
transportDocumentLines: List[TransportDocumentLineDTO],
totalWeight: Double,
)
final case class TransportDocumentLineDTO(quantity: Int, product: ProductDTO, price: Int)
object TransportDocumentDTO:
given DTO[TransportDocument, TransportDocumentDTO] = interCaseClassDTO
private given DTO[TransportDocumentLine, TransportDocumentLineDTO] = interCaseClassDTO

0 comments on commit 27973fe

Please sign in to comment.