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

@ -3,7 +3,7 @@ module git.fjla.uk/owlboard/mq-client
go 1.19
require (
git.fjla.uk/owlboard/go-types v0.0.0-20230720095555-ad24002a6acc
git.fjla.uk/owlboard/go-types v0.0.0-20230720100930-1cbfb1d074d2
github.com/go-stomp/stomp/v3 v3.0.5
go.mongodb.org/mongo-driver v1.12.0
go.uber.org/zap v1.24.0

View File

@ -12,6 +12,8 @@ git.fjla.uk/owlboard/go-types v0.0.0-20230719192727-845a41f8572b h1:QKHrP3kjvypP
git.fjla.uk/owlboard/go-types v0.0.0-20230719192727-845a41f8572b/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
git.fjla.uk/owlboard/go-types v0.0.0-20230720095555-ad24002a6acc h1:7s+svu/FOU/qwLLThtwvOV2CqID8sZmVyd15UldgBR8=
git.fjla.uk/owlboard/go-types v0.0.0-20230720095555-ad24002a6acc/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
git.fjla.uk/owlboard/go-types v0.0.0-20230720100930-1cbfb1d074d2 h1:FOLnHCAL/2fnjC/TLpQkt4WSMzijcDrtyf0YdiyZIbo=
git.fjla.uk/owlboard/go-types v0.0.0-20230720100930-1cbfb1d074d2/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

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
}