Add 'Create' & 'Delete' database actions

This commit is contained in:
Fred Boniface
2023-07-27 20:51:21 +01:00
parent 5005030099
commit 06f59fcfea
4 changed files with 48 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"git.fjla.uk/owlboard/go-types/pkg/database"
"git.fjla.uk/owlboard/mq-client/dbAccess"
"git.fjla.uk/owlboard/mq-client/log"
)
@@ -25,6 +26,12 @@ func processEntryType(entry database.Service) {
func createEntry(entry database.Service) {
log.Msg.Info("Entry Creation requested for: " + entry.TrainUid + " - " + entry.Headcode + " - " + entry.Operator)
status := dbAccess.PutOneService(entry)
if status {
log.Msg.Info("Database entry created")
} else {
log.Msg.Error("Database entry failed, skipped service")
}
}
func updateEntry(entry database.Service) {
@@ -33,5 +40,16 @@ func updateEntry(entry database.Service) {
func deleteEntry(entry database.Service) {
log.Msg.Info("Entry DELETE requested for: " + entry.TrainUid + " - " + entry.Headcode)
fmt.Printf("%+v\n", entry)
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)
}
}