From f14b3b3288cb5ff9cd198eafb89ab61ca88020d0 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 4 Oct 2024 12:26:54 +0200 Subject: [PATCH] Implement order status updating --- .../synqapi/SynqMessageController.kt | 8 +++----- .../kotlin/no/nb/mlt/wls/domain/WLSService.kt | 17 +++++++++++++++++ .../kotlin/no/nb/mlt/wls/domain/model/Order.kt | 4 ++++ .../mlt/wls/domain/ports/inbound/UpdateOrder.kt | 8 ++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/synqapi/SynqMessageController.kt b/src/main/kotlin/no/nb/mlt/wls/application/synqapi/SynqMessageController.kt index 22dfbccd..d7a9ce79 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/synqapi/SynqMessageController.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/synqapi/SynqMessageController.kt @@ -12,15 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -// TODO - Repackage @RestController @RequestMapping("/synq/v1") class SynqMessageController( -// private val updateItem: UpdateItem, - private val updateOrder: UpdateOrder + val updateOrder: UpdateOrder ) { @PutMapping("/order-update/{owner}/{orderId}") - fun handleStatusUpdate( + suspend fun handleStatusUpdate( @PathVariable owner: String, @PathVariable orderId: String, @RequestBody payload: OrderStatusUpdate, @@ -28,7 +26,7 @@ class SynqMessageController( ) { println("Hello world! Order update received") println(payload) - TODO("update the order") + updateOrder.updateOrderStatus(payload.hostName, orderId, payload.status) } @PutMapping("/pick-update/{owner}/{orderId}") diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt index e45715d6..2c577c4c 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt @@ -131,6 +131,23 @@ class WLSService( return orderRepository.updateOrder(result) } + override suspend fun updateOrderStatus( + hostName: HostName, + hostOrderId: String, + status: String + ): Order { + val order = + getOrder( + hostName, + hostOrderId + ) ?: throw OrderNotFoundException("No order with hostOrderId: $hostOrderId and hostName: $hostName exists") + + val updatedOrder = order.setStatus(Order.Status.valueOf(status)) + + val result = storageSystemFacade.updateOrder(updatedOrder) + return orderRepository.updateOrder(result) + } + override suspend fun getOrder( hostName: HostName, hostOrderId: String diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 868a6b77..3e87abae 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -63,6 +63,10 @@ data class Order( return this.copy(orderType = orderType) } + fun setStatus(status: Status): Order { + return this.copy(status = status) + } + fun setCallbackUrl(callbackUrl: String): Order { throwIfInvalidUrl(callbackUrl) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt index 1490e317..0cc12eaf 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt @@ -15,6 +15,14 @@ interface UpdateOrder { receiver: Order.Receiver, callbackUrl: String ): Order + + // TODO - Should this be split off into its own use-case/interface? + @Throws(OrderNotFoundException::class) + suspend fun updateOrderStatus( + hostName: HostName, + hostOrderId: String, + status: String + ): Order } class IllegalOrderStateException(override val message: String, cause: Throwable? = null) : RuntimeException(message, cause)