2023-07-19 21:31:00 +01:00
|
|
|
package vstp
|
|
|
|
|
2023-07-21 12:12:16 +01:00
|
|
|
import (
|
2023-07-21 21:20:44 +01:00
|
|
|
"fmt"
|
|
|
|
|
2023-07-21 12:12:16 +01:00
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
2023-07-27 20:51:21 +01:00
|
|
|
"git.fjla.uk/owlboard/mq-client/dbAccess"
|
2023-07-21 12:12:16 +01:00
|
|
|
"git.fjla.uk/owlboard/mq-client/log"
|
|
|
|
)
|
|
|
|
|
2023-07-19 21:31:00 +01:00
|
|
|
// Decide, based on the DB Formatted message type, what action needs taking
|
|
|
|
// then either insert, or delete from the database as required
|
2023-07-21 12:12:16 +01:00
|
|
|
func processEntryType(entry database.Service) {
|
2023-07-22 09:01:45 +01:00
|
|
|
|
|
|
|
switch entry.TransactionType {
|
|
|
|
case "Create":
|
2023-07-21 12:12:16 +01:00
|
|
|
createEntry(entry)
|
2023-07-22 09:01:45 +01:00
|
|
|
case "Update":
|
|
|
|
updateEntry(entry)
|
|
|
|
case "Delete":
|
2023-07-21 12:12:16 +01:00
|
|
|
deleteEntry(entry)
|
2023-07-22 09:01:45 +01:00
|
|
|
default:
|
|
|
|
log.Msg.Error("Unknown transaction type: " + entry.TransactionType)
|
2023-07-21 12:12:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createEntry(entry database.Service) {
|
2023-07-21 14:40:24 +01:00
|
|
|
log.Msg.Info("Entry Creation requested for: " + entry.TrainUid + " - " + entry.Headcode + " - " + entry.Operator)
|
2023-07-27 20:51:21 +01:00
|
|
|
status := dbAccess.PutOneService(entry)
|
|
|
|
if status {
|
|
|
|
log.Msg.Info("Database entry created")
|
|
|
|
} else {
|
|
|
|
log.Msg.Error("Database entry failed, skipped service")
|
|
|
|
}
|
2023-07-21 12:12:16 +01:00
|
|
|
}
|
|
|
|
|
2023-07-22 09:01:45 +01:00
|
|
|
func updateEntry(entry database.Service) {
|
|
|
|
log.Msg.Info("Entry UPDATE requested for: " + entry.TrainUid + " - " + entry.Headcode + " - " + entry.Operator)
|
|
|
|
}
|
|
|
|
|
2023-07-21 12:12:16 +01:00
|
|
|
func deleteEntry(entry database.Service) {
|
|
|
|
log.Msg.Info("Entry DELETE requested for: " + entry.TrainUid + " - " + entry.Headcode)
|
2023-07-27 20:51:21 +01:00
|
|
|
var deletionQuery = database.DeleteQuery{
|
|
|
|
TrainUid: entry.TrainUid,
|
|
|
|
ScheduleStartDate: entry.ScheduleStartDate,
|
|
|
|
StpIndicator: entry.StpIndicator,
|
|
|
|
}
|
|
|
|
status := dbAccess.DeleteOneService(deletionQuery)
|
|
|
|
if status {
|
|
|
|
log.Msg.Info("Database entry deleted")
|
|
|
|
} else {
|
|
|
|
log.Msg.Error("Database deletion failed, skipped deletion")
|
|
|
|
fmt.Printf("%+v\n", deletionQuery)
|
|
|
|
}
|
2023-07-21 12:12:16 +01:00
|
|
|
}
|