From 47cc879b6ec589b05275e8b56693ac38e17df623 Mon Sep 17 00:00:00 2001 From: Jonah Greenthal Date: Sat, 25 Nov 2023 21:44:02 -0600 Subject: [PATCH] make sure sequence is always set --- .../order/controller/InvoiceLineController.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/reinsteinquizbowl/order/controller/InvoiceLineController.kt b/src/main/kotlin/com/reinsteinquizbowl/order/controller/InvoiceLineController.kt index 4c032f6..ac96a9e 100644 --- a/src/main/kotlin/com/reinsteinquizbowl/order/controller/InvoiceLineController.kt +++ b/src/main/kotlin/com/reinsteinquizbowl/order/controller/InvoiceLineController.kt @@ -53,6 +53,9 @@ class InvoiceLineController { fun addLine(@PathVariable bookingCreationId: String, @RequestBody input: ApiInvoiceLine): ApiBooking { val booking = bookingService.findThenAuthorize(bookingCreationId) + val sequence: Long = input.sequence + ?: ((repo.findByBookingId(booking.id!!).mapNotNull(InvoiceLine::sequence).maxOrNull() ?: 0) + 1) + repo.save( InvoiceLine( bookingId = booking.id, @@ -61,7 +64,7 @@ class InvoiceLineController { label = input.label, quantity = input.quantity, unitCost = input.unitCost, - sequence = input.sequence, + sequence = sequence, ) )