Adjust formatting functions

This commit is contained in:
Fred Boniface
2023-07-20 12:01:20 +01:00
parent 5ee737f3f8
commit 362779f7de
3 changed files with 10 additions and 8 deletions

View File

@@ -18,7 +18,6 @@ func unmarshalData(jsonData string) database.Service {
fmt.Println(jsonData)
log.Msg.Debug("Converting to byte array")
jsonDataBytes := []byte(jsonData)
fmt.Println(jsonDataBytes)
var schedule upstreamApi.VstpMsg
err := json.Unmarshal(jsonDataBytes, &schedule)
if err != nil {
@@ -32,19 +31,20 @@ func unmarshalData(jsonData string) database.Service {
}
// Transforms the upstreamApi.Schedule type into a database.Service type
func formatData(dataInput upstreamApi.Schedule) database.Service {
func formatData(dataInput *upstreamApi.Schedule) database.Service {
log.Msg.Debug("ScheduleSegment length: " + fmt.Sprint(len(dataInput.ScheduleSegment)))
service := database.Service{
TransactionType: dataInput.TransactionType,
StpIndicator: dataInput.CIFSTPIndicator,
Operator: dataInput.ScheduleSegment.ATOCCode,
Operator: dataInput.ScheduleSegment[0].ATOCCode,
TrainUid: dataInput.CIFTrainUID,
Headcode: dataInput.ScheduleSegment.SignallingID,
PowerType: dataInput.ScheduleSegment.CIFPowerType,
PlanSpeed: parseSpeed(dataInput.ScheduleSegment.CIFSpeed),
Headcode: dataInput.ScheduleSegment[0].SignallingID,
PowerType: dataInput.ScheduleSegment[0].CIFPowerType,
PlanSpeed: parseSpeed(dataInput.ScheduleSegment[0].CIFSpeed),
ScheduleStartDate: parseDate(dataInput.ScheduleStartDate, false),
ScheduleEndDate: parseDate(dataInput.ScheduleEndDate, true),
DaysRun: parseDaysRun(dataInput.ScheduleDaysRun),
Stops: parseStops(dataInput.ScheduleSegment.ScheduleLocation),
Stops: parseStops(dataInput.ScheduleSegment[0].ScheduleLocation),
}
return service
}