diff --git a/src/main/kotlin/com/reinsteinquizbowl/order/repository/BookingRepository.kt b/src/main/kotlin/com/reinsteinquizbowl/order/repository/BookingRepository.kt index 6a25621..1a3ffe6 100644 --- a/src/main/kotlin/com/reinsteinquizbowl/order/repository/BookingRepository.kt +++ b/src/main/kotlin/com/reinsteinquizbowl/order/repository/BookingRepository.kt @@ -16,10 +16,4 @@ interface BookingRepository : CrudRepository { nativeQuery = true ) fun countLowerIdBookingsForSchoolId(schoolId: Long, bookingId: Long): Long - - @Query( - "select count(*) from booking where school_id is null and id < ?1", - nativeQuery = true - ) - fun countLowerIdBookingsForNoSchool(bookingId: Long): Long } diff --git a/src/main/kotlin/com/reinsteinquizbowl/order/service/Converter.kt b/src/main/kotlin/com/reinsteinquizbowl/order/service/Converter.kt index 4513680..065a882 100644 --- a/src/main/kotlin/com/reinsteinquizbowl/order/service/Converter.kt +++ b/src/main/kotlin/com/reinsteinquizbowl/order/service/Converter.kt @@ -58,7 +58,7 @@ class Converter { return ApiBooking( id = entity.id, - school = entity.school?.let { toApi(it) }, + school = toApi(entity.school!!), name = entity.name, emailAddress = entity.emailAddress, authority = entity.authority, diff --git a/src/main/kotlin/com/reinsteinquizbowl/order/service/InvoiceCalculator.kt b/src/main/kotlin/com/reinsteinquizbowl/order/service/InvoiceCalculator.kt index caf6be4..16afa45 100644 --- a/src/main/kotlin/com/reinsteinquizbowl/order/service/InvoiceCalculator.kt +++ b/src/main/kotlin/com/reinsteinquizbowl/order/service/InvoiceCalculator.kt @@ -40,18 +40,12 @@ class InvoiceCalculator { @Autowired private lateinit var invoiceLineRepo: InvoiceLineRepository fun determineInvoiceLabel(booking: Booking): String { - val schoolId = booking.school?.id + val schoolId = booking.school!!.id!! - val bookingsWithLowerId = if (schoolId == null) { - repo.countLowerIdBookingsForNoSchool(booking.id!!) - } else { - repo.countLowerIdBookingsForSchoolId(schoolId, booking.id!!) - } + val bookingsWithLowerId = repo.countLowerIdBookingsForSchoolId(schoolId, booking.id!!) val thisBookingSequence = bookingsWithLowerId + 1 - val displayableSchoolId = schoolId?.toString() ?: "X" - - return "$displayableSchoolId-$thisBookingSequence" + return "$schoolId-$thisBookingSequence" } // This logic is described in the UI, so when updating it, it should be updated in both places. diff --git a/src/main/resources/db/creation.sql b/src/main/resources/db/creation.sql index af98c10..f0ca10b 100644 --- a/src/main/resources/db/creation.sql +++ b/src/main/resources/db/creation.sql @@ -69,7 +69,7 @@ create table booking_status ( -- I wanted to call this `order`, but that's a SQL reserved word create table booking ( id serial primary key, - school_id int null references school, + school_id int not null references school, name text not null, email_address text not null, authority text null,