Update CIF Conversion function to new ServiceDetail subdoc.
This commit is contained in:
@@ -2,6 +2,7 @@ package cif
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.fjla.uk/owlboard/go-types/pkg/database"
|
||||
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
||||
@@ -14,7 +15,6 @@ func ConvertServiceType(input *upstreamApi.JsonScheduleV1, vstp bool) (*database
|
||||
output := database.Service{
|
||||
TransactionType: input.TransactionType,
|
||||
StpIndicator: input.CifStpIndicator,
|
||||
Vstp: vstp, // Simply uses the value passed into the function
|
||||
Operator: input.AtocCode,
|
||||
TrainUid: input.CifTrainUid,
|
||||
Headcode: input.ScheduleSegment.SignallingId,
|
||||
@@ -22,9 +22,7 @@ func ConvertServiceType(input *upstreamApi.JsonScheduleV1, vstp bool) (*database
|
||||
PlanSpeed: parseSpeed(&input.ScheduleSegment.CifSpeed),
|
||||
ScheduleStartDate: ParseCifDate(&input.ScheduleStartDate, "start"),
|
||||
ScheduleEndDate: ParseCifDate(&input.ScheduleEndDate, "end"),
|
||||
FirstClass: hasFirstClass(&input.ScheduleSegment.CifTrainClass, &input.ScheduleSegment.SignallingId),
|
||||
Catering: hasCatering(&input.ScheduleSegment.CifCateringCode),
|
||||
Sleeper: hasSleeper(&input.ScheduleSegment.CifSleepers),
|
||||
ServiceDetail: generateServiceDetail(&input.ScheduleSegment.CifTrainClass, &input.ScheduleSegment.SignallingId, &input.ScheduleSegment.CifCateringCode, &input.ScheduleSegment.CifSleepers, &input.ScheduleSegment.CifOperatingCharacteristics, vstp),
|
||||
DaysRun: parseDaysRun(&input.ScheduleDaysRun),
|
||||
Stops: parseStops(&input.ScheduleSegment.ScheduleLocation),
|
||||
}
|
||||
@@ -85,6 +83,22 @@ func isPublic(input *upstreamApi.CifScheduleLocation) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Generates a ServiceDetail struct based on the input
|
||||
func generateServiceDetail(
|
||||
cifTrainClass, signallingId,
|
||||
cateringCode, sleepers,
|
||||
operatingCharacteristics *string,
|
||||
vstp bool,
|
||||
) database.ServiceDetail {
|
||||
return database.ServiceDetail{
|
||||
FirstClass: hasFirstClass(cifTrainClass, signallingId),
|
||||
Catering: hasCatering(cateringCode),
|
||||
Sleeper: hasSleeper(sleepers),
|
||||
Vstp: vstp,
|
||||
Guard: hasGuard(operatingCharacteristics),
|
||||
}
|
||||
}
|
||||
|
||||
// Ascertains whether the service offers first class
|
||||
func hasFirstClass(input, signallingId *string) bool {
|
||||
if input == nil || signallingId == nil {
|
||||
@@ -115,3 +129,9 @@ func hasSleeper(input *string) bool {
|
||||
}
|
||||
return *input != ""
|
||||
}
|
||||
|
||||
// Ascertains whether the service requires a guard
|
||||
func hasGuard(opChars *string) bool {
|
||||
str := strings.ToLower(*opChars)
|
||||
return strings.Contains(str, "g")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user