package vstp import ( "fmt" "git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi" "git.fjla.uk/owlboard/timetable-mgr/cif" "git.fjla.uk/owlboard/timetable-mgr/dbAccess" ) // Converts to the correct struct for database insertion, then processes accordingly func processCifData(s *upstreamApi.JsonScheduleV1) error { if s.TransactionType == "Create" { service, err := cif.ConvertServiceType(s, true) if err != nil { return err } // Create slice as required by CreateCifEntries() services := []database.Service{*service} err = dbAccess.CreateCifEntries(services) if err != nil { return err } return nil } else if s.TransactionType == "Delete" { query := database.DeleteQuery{ TrainUid: s.CifTrainUid, ScheduleStartDate: cif.ParseCifDate(&s.ScheduleStartDate, "start"), StpIndicator: s.CifStpIndicator, } // Create slice as required by DeleteCifEntries() queries := []database.DeleteQuery{query} err := dbAccess.DeleteCifEntries(queries) if err != nil { return err } return nil } else { return fmt.Errorf("unknown transaction type: %s", s.TransactionType) } }