From 693ba6551ff9371ea861a33a214ff208c2616b66 Mon Sep 17 00:00:00 2001 From: Jarkko Kaura Date: Tue, 17 Oct 2023 09:00:46 +0300 Subject: [PATCH] Change `HasuraErrorExtensions` from sealed class to sealed interface. --- .../api/util/HasuraErrorExtensions.kt | 69 ++++++++++++++----- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorExtensions.kt b/src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorExtensions.kt index d476e5d..c38cbd4 100644 --- a/src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorExtensions.kt +++ b/src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorExtensions.kt @@ -4,35 +4,68 @@ import fi.hsl.jore4.timetables.enumerated.TimetablesPriority import org.springframework.http.HttpStatus import java.util.UUID -sealed class HasuraErrorExtensions(httpStatus: HttpStatus) { +sealed interface HasuraErrorExtensions { + // code must be 4xx - val code: Int = httpStatus.value() + val code: Int } -class PlainStatusExtensions(httpStatus: HttpStatus) : HasuraErrorExtensions(httpStatus) +data class PlainStatusExtensions(override val code: Int) : HasuraErrorExtensions { + + constructor(httpStatus: HttpStatus) : this(httpStatus.value()) +} -class InvalidTargetPriorityExtensions( - httpStatus: HttpStatus, +data class InvalidTargetPriorityExtensions( + override val code: Int, val targetPriority: TimetablesPriority -) : HasuraErrorExtensions(httpStatus) +) : HasuraErrorExtensions { -class StagingVehicleScheduleFrameNotFoundExtensions( - httpStatus: HttpStatus, + constructor(httpStatus: HttpStatus, targetPriority: TimetablesPriority) : this(httpStatus.value(), targetPriority) +} + +data class StagingVehicleScheduleFrameNotFoundExtensions( + override val code: Int, val stagingVehicleScheduleFrameId: UUID -) : HasuraErrorExtensions(httpStatus) +) : HasuraErrorExtensions { + + constructor(httpStatus: HttpStatus, stagingVehicleScheduleFrameId: UUID) : this( + httpStatus.value(), + stagingVehicleScheduleFrameId + ) +} -class TargetVehicleScheduleFrameNotFoundExtensions( - httpStatus: HttpStatus, +data class TargetVehicleScheduleFrameNotFoundExtensions( + override val code: Int, val stagingVehicleScheduleFrameId: UUID -) : HasuraErrorExtensions(httpStatus) +) : HasuraErrorExtensions { -class MultipleTargetFramesFoundExtensions( - httpStatus: HttpStatus, + constructor(httpStatus: HttpStatus, stagingVehicleScheduleFrameId: UUID) : this( + httpStatus.value(), + stagingVehicleScheduleFrameId + ) +} + +data class MultipleTargetFramesFoundExtensions( + override val code: Int, val stagingVehicleScheduleFrameId: UUID, val targetVehicleScheduleFrameIds: List -) : HasuraErrorExtensions(httpStatus) +) : HasuraErrorExtensions { + + constructor( + httpStatus: HttpStatus, + stagingVehicleScheduleFrameId: UUID, + targetVehicleScheduleFrameIds: List + ) : this( + httpStatus.value(), + stagingVehicleScheduleFrameId, + targetVehicleScheduleFrameIds + ) +} -class TargetPriorityParsingExtensions( - httpStatus: HttpStatus, +data class TargetPriorityParsingExtensions( + override val code: Int, val targetPriority: Int -) : HasuraErrorExtensions(httpStatus) +) : HasuraErrorExtensions { + + constructor(httpStatus: HttpStatus, targetPriority: Int) : this(httpStatus.value(), targetPriority) +}