Skip to content

Commit

Permalink
Add comments to OrderService
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheroneofthese committed Aug 27, 2024
1 parent a2bdaff commit 3e41b62
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/kotlin/no/nb/mlt/wls/order/service/OrderService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,31 @@ class OrderService(val db: OrderRepository, val synqService: SynqOrderService) {
return ResponseEntity.status(HttpStatus.CREATED).body(order.toApiOrderPayload())
}

private fun throwIfInvalidPayload(payload: ApiOrderPayload) {
if (payload.orderId.isBlank()) {
throw ServerWebInputException("The order's orderId is required, and can not be blank")
}
if (payload.hostOrderId.isBlank()) {
throw ServerWebInputException("The order's hostOrderId is required, and can not be blank")
}
if (payload.productLine.isEmpty()) {
throw ServerWebInputException("The order must contain product lines")
}
}

/**
* Gets an order from the WLS database
*/
suspend fun getOrder(
hostName: HostName,
hostOrderId: String
): ResponseEntity<Order> {
val order =
db.findByHostNameAndHostOrderId(hostName, hostOrderId)
.onErrorMap(IncorrectResultSizeDataAccessException::class.java) {
TODO("Handle duplicate order ID's somehow")
}
.awaitSingleOrNull()
if (order != null) {
return ResponseEntity.ok(order)
}
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Order with id $hostOrderId from $hostName was not found")
}

private fun throwIfInvalidPayload(payload: ApiOrderPayload) {
if (payload.orderId.isBlank()) {
throw ServerWebInputException("The order's orderId is required, and can not be blank")
}
if (payload.hostOrderId.isBlank()) {
throw ServerWebInputException("The order's hostOrderId is required, and can not be blank")
}
if (payload.productLine.isEmpty()) {
throw ServerWebInputException("The order must contain product lines")
}
}
}

0 comments on commit 3e41b62

Please sign in to comment.