56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package vstp
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
|
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
|
|
"git.fjla.uk/owlboard/timetable-mgr/log"
|
|
)
|
|
|
|
// Decide, based on the DB Formatted message type, what action needs taking
|
|
// then either insert, or delete from the database as required
|
|
func processEntryType(entry database.Service) {
|
|
|
|
switch entry.TransactionType {
|
|
case "Create":
|
|
createEntry(entry)
|
|
case "Update":
|
|
updateEntry(entry)
|
|
case "Delete":
|
|
deleteEntry(entry)
|
|
default:
|
|
log.Warn("Unknown transaction type: " + entry.TransactionType)
|
|
}
|
|
}
|
|
|
|
func createEntry(entry database.Service) {
|
|
log.Info("Entry Creation requested for: " + entry.TrainUid + " - " + entry.Headcode + " - " + entry.Operator)
|
|
status := dbAccess.PutOneService(entry)
|
|
if status {
|
|
log.Info("Database entry created")
|
|
} else {
|
|
log.Error("Database entry failed, skipped service")
|
|
}
|
|
}
|
|
|
|
func updateEntry(entry database.Service) {
|
|
log.Warn("Entry UPDATE requested for: " + entry.TrainUid + " - " + entry.Headcode + " - " + entry.Operator)
|
|
}
|
|
|
|
func deleteEntry(entry database.Service) {
|
|
log.Info("Entry DELETE requested for: " + entry.TrainUid + " - " + entry.Headcode)
|
|
var deletionQuery = database.DeleteQuery{
|
|
TrainUid: entry.TrainUid,
|
|
ScheduleStartDate: entry.ScheduleStartDate,
|
|
StpIndicator: entry.StpIndicator,
|
|
}
|
|
status := dbAccess.DeleteOneService(deletionQuery)
|
|
if status {
|
|
log.Info("Database entry deleted")
|
|
} else {
|
|
log.Error("Database deletion failed, skipped deletion")
|
|
fmt.Printf("%+v\n", deletionQuery)
|
|
}
|
|
}
|