From de0e7d6fb62ab704f236ef81959086283ef5db47 Mon Sep 17 00:00:00 2001 From: Frikky Date: Mon, 27 May 2024 23:40:08 +0200 Subject: [PATCH] Fixed backend --- db-connector.go | 29 ++++++++++++++++++++++++++++- structs.go | 12 ++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/db-connector.go b/db-connector.go index ee50724..5b71444 100755 --- a/db-connector.go +++ b/db-connector.go @@ -7521,7 +7521,7 @@ func SetWorkflow(ctx context.Context, workflow Workflow, id string, optionalEdit // New struct, to not add body, author etc data, err := json.Marshal(workflow) if err != nil { - log.Printf("[WARNING] Failed marshalling in getworkflow: %s", err) + log.Printf("[WARNING] Failed marshalling in set workflow: %s", err) return nil } @@ -12803,3 +12803,30 @@ func DeleteDbIndex(ctx context.Context, index string) error { return nil } + +func SetTraining(ctx context.Context, training Training) error { + if project.DbType == "opensearch" { + return errors.New("Not implemented") + } + + if training.ID == "" { + training.ID = uuid.NewV4().String() + } + + if training.SignupTime == 0 { + training.SignupTime = time.Now().Unix() + } + + // Overwriting to be sure these are matching + // No real point in having id + workflow.ID anymore + nameKey := "training" + + log.Printf("[INFO] Setting training with %d attendants", training.NumberOfAttendees) + key := datastore.NameKey(nameKey, training.ID, nil) + if _, err := project.Dbclient.Put(ctx, key, &training); err != nil { + log.Printf("[ERROR] Failed adding training with ID %s: %s", training.ID, err) + return err + } + + return nil +} diff --git a/structs.go b/structs.go index 377a7e0..774db07 100755 --- a/structs.go +++ b/structs.go @@ -3865,3 +3865,15 @@ type SSOResponse struct { Reason string `json:"reason"` URL string `json:"url"` } + +type Training struct { + Name string `json:"Name"` + Email string `json:"Email"` + NumberOfAttendees int `json:"numberOfAttendees"` + Message string `json:"Message"` + Time string `json:"Time"` + Country string `json:"Country"` + + ID string `json:"id"` + SignupTime int64 `json:"signupTime"` +}