Skip to content

Commit

Permalink
Implement order status updating
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheroneofthese committed Oct 4, 2024
1 parent e5b7794 commit f14b3b3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ 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,
@AuthenticationPrincipal caller: JwtAuthenticationToken
) {
println("Hello world! Order update received")
println(payload)
TODO("update the order")
updateOrder.updateOrderStatus(payload.hostName, orderId, payload.status)
}

@PutMapping("/pick-update/{owner}/{orderId}")
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f14b3b3

Please sign in to comment.