Review this route before it accepts production orders.
Authenticate the tenant, validate an order, create it durably and idempotently, and publish a notification after commit.
kotlin
fun Route.orderRoutes(
service: OrderService,
notifications: Notifications,
) {
post("/orders") {
val request = call.receive<CreateOrderRequest>()
val tenantId = call.request.headers["X-Tenant"]!!
val key = call.request.headers["Idempotency-Key"]
val existing = service.findByKey(key)
if (existing != null) return@post call.respond(existing)
val order = service.create(tenantId, request)
GlobalScope.launch {
notifications.send(order)
}
call.respond(HttpStatusCode.Created, order)
}
}
generated code is illustrative, not from any one model