Skip to content

Commit

Permalink
Refactor: move target vehicle schedule frame fetching to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Leitsi committed Dec 4, 2023
1 parent c67b634 commit 99e9cba
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ class CombineTimetablesService(

val stagingVehicleScheduleFrame = fetchStagingVehicleScheduleFrame(stagingVehicleScheduleFrameId)

val targetVehicleScheduleFrame = fetchTargetVehicleScheduleFrame(stagingVehicleScheduleFrame, targetPriority)

LOGGER.info("Moving staging vehicle services to target...")
moveStagingVehicleServicesToTarget(
stagingFrame = stagingVehicleScheduleFrame,
targetFrame = targetVehicleScheduleFrame
)

LOGGER.info("Deleting the empty staging frame...")
deleteStagingVehicleScheduleFrame(stagingVehicleScheduleFrameId)

return targetVehicleScheduleFrame.vehicleScheduleFrameId!! // ID of an existing row, can never be null.
}

private fun fetchTargetVehicleScheduleFrame(
stagingVehicleScheduleFrame: VehicleScheduleFrame,
targetPriority: TimetablesPriority
): VehicleScheduleFrame {
// ID of an existing row, can never be null.
val stagingVehicleScheduleFrameId = stagingVehicleScheduleFrame.vehicleScheduleFrameId!!

val targetVehicleScheduleFrames = vehicleScheduleFrameRepository
.fetchTargetVehicleScheduleFrames(stagingVehicleScheduleFrame, targetPriority)
LOGGER.info { "Found ${targetVehicleScheduleFrames.size} target vehicle schedule frames." }
Expand All @@ -61,16 +82,7 @@ class CombineTimetablesService(
)
}

LOGGER.info("Moving staging vehicle services to target...")
moveStagingVehicleServicesToTarget(
stagingFrame = stagingVehicleScheduleFrame,
targetFrame = targetVehicleScheduleFrame
)

LOGGER.info("Deleting the empty staging frame...")
deleteStagingVehicleScheduleFrame(stagingVehicleScheduleFrameId)

return targetVehicleScheduleFrame.vehicleScheduleFrameId!! // ID of an existing row, can never be null.
return targetVehicleScheduleFrame
}

private fun fetchStagingVehicleScheduleFrame(stagingVehicleScheduleFrameId: UUID): VehicleScheduleFrame {
Expand Down

0 comments on commit 99e9cba

Please sign in to comment.