timetable-extension #1

Open
fred.boniface wants to merge 160 commits from timetable-extension into main
2 changed files with 34 additions and 2 deletions
Showing only changes of commit a15cbb778a - Show all commits

View File

@ -1,8 +1,11 @@
package cif package cif
import ( import (
"time"
"git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/go-types/pkg/database"
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
"git.fjla.uk/owlboard/timetable-mgr/log" "git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -51,6 +54,13 @@ func doDeletions(deletions []*upstreamApi.JsonScheduleV1) error {
deleteQueries = append(deleteQueries, query) deleteQueries = append(deleteQueries, query)
} }
err := dbAccess.DeleteCifEntries(deleteQueries)
if err != nil {
log.Msg.Error("Error deleting documents", zap.Error(err))
return err
}
return nil return nil
} }
@ -61,8 +71,27 @@ func doCreations(creations []*upstreamApi.JsonScheduleV1) error {
createDocuments := make([]database.Service, 0) createDocuments := make([]database.Service, 0)
for _, item := range creations { for _, item := range creations {
document := database.Service{} document := database.Service{}
// Do type conversion here
createDocuments = append(createDocuments, document) createDocuments = append(createDocuments, document)
} }
err := dbAccess.CreateCifEntries(createDocuments)
if err != nil {
log.Msg.Error("Error creating documents", zap.Error(err))
return err
}
return nil return nil
} }
// Accepts the JsonTimetableV1 struct which contains CIF File metadata and produces a DB Ready struct.
func generateMetadata(header *upstreamApi.JsonTimetableV1) *dbAccess.CifMetadata {
newMetadata := dbAccess.CifMetadata{
Doctype: dbAccess.Doctype,
LastTimestamp: header.Timestamp,
LastUpdate: time.Now().In(londonTimezone),
LastSequence: header.Metadata.Sequence,
}
return &newMetadata
}

View File

@ -68,10 +68,13 @@ func runCifUpdateDownload(cfg *helpers.Configuration, metadata *dbAccess.CifMeta
// Check metadata sequence - Handle a metadata sequence error. Probably by deleting metadata so next update triggers full download // Check metadata sequence - Handle a metadata sequence error. Probably by deleting metadata so next update triggers full download
//// I need to check what the sequence looks like in a full download first. //// I need to check what the sequence looks like in a full download first.
//// Regarding metadata, I will need to replace 'metadata *dbAccess.CifMetadata' with the new metadata to ensure it is checked correctly in each iteration.
// Process CIF file // Process CIF file
// Generate & Write metadata // Update metadata variable
} }
// Write metadata
return nil return nil
} }