timetable-extension #1
@ -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")
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.fjla.uk/owlboard/timetable-mgr
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
git.fjla.uk/owlboard/go-types v1.0.1
|
||||
git.fjla.uk/owlboard/go-types v1.1.0
|
||||
github.com/go-stomp/stomp/v3 v3.1.0
|
||||
go.mongodb.org/mongo-driver v1.15.0
|
||||
go.uber.org/zap v1.27.0
|
||||
|
2
go.sum
2
go.sum
@ -16,6 +16,8 @@ git.fjla.uk/owlboard/go-types v1.0.0 h1:yL/F97CzAnk9Ui4T9sC4k7Fc1H4mZgbesMRIwlYE
|
||||
git.fjla.uk/owlboard/go-types v1.0.0/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
|
||||
git.fjla.uk/owlboard/go-types v1.0.1 h1:APZS0jQUjdaNPfWijToX6LLA+g4aI8ZYPXQVS5aN1eg=
|
||||
git.fjla.uk/owlboard/go-types v1.0.1/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
|
||||
git.fjla.uk/owlboard/go-types v1.1.0 h1:3o8My2O3KMOtSjXApYyI3VBS03PPdk+NGt7QonoFkl0=
|
||||
git.fjla.uk/owlboard/go-types v1.1.0/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
Loading…
Reference in New Issue
Block a user