Skip to content

Commit

Permalink
Change HasuraErrorExtensions from sealed class to sealed interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
jarkkoka committed Oct 17, 2023
1 parent c77bf8b commit 693ba65
Showing 1 changed file with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID>
) : HasuraErrorExtensions(httpStatus)
) : HasuraErrorExtensions {

constructor(
httpStatus: HttpStatus,
stagingVehicleScheduleFrameId: UUID,
targetVehicleScheduleFrameIds: List<UUID>
) : 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)
}

0 comments on commit 693ba65

Please sign in to comment.