From 8a03ad205df1294dc3a7aa57b07dc6a5552aaa93 Mon Sep 17 00:00:00 2001 From: pb Date: Fri, 22 Mar 2024 11:27:25 +0100 Subject: [PATCH] added user input handling methods --- models/computing.go | 20 ++++++++++++++++++++ models/storage.go | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/models/computing.go b/models/computing.go index d3c58e1..846f06d 100644 --- a/models/computing.go +++ b/models/computing.go @@ -1,6 +1,9 @@ package models import ( + "fmt" + "strings" + "cloud.o-forge.io/core/oc-catalog/models/rtype" "cloud.o-forge.io/core/oc-catalog/services" "github.com/beego/beego/v2/core/logs" @@ -170,3 +173,20 @@ func GetMultipleComputing(IDs []string) (object *[]ComputingModel, err error) { func PostOneComputing(obj ComputingNEWModel) (ID string, err error) { return postOneResource(obj, rtype.COMPUTING) } + +func (obj ComputingModel) AddUserInput(inputs map[string]interface{} ){ + // So far only a few input to handle so a switch with a case for each type of attribute + // is enough, to prevent too much complexity + for key, value := range inputs { + switch strings.ToLower(key) { + case "command": + obj.Command = value.(string) + case "arguments": + obj.Arguments = value.([]string) + case "env" : + obj.Environment = value.([]string) + default: + logs.Alert(fmt.Printf("%s is not an attribute of storage componants", key)) + } + } +} \ No newline at end of file diff --git a/models/storage.go b/models/storage.go index 397cd82..245f34f 100644 --- a/models/storage.go +++ b/models/storage.go @@ -1,6 +1,9 @@ package models import ( + "fmt" + "strings" + "cloud.o-forge.io/core/oc-catalog/models/rtype" "cloud.o-forge.io/core/oc-catalog/services" "github.com/beego/beego/v2/core/logs" @@ -12,7 +15,7 @@ type StorageNEWModel struct { Description string `json:"description" required:"true"` ShortDescription string `json:"short_description" required:"true" validate:"required"` Logo string `json:"logo" required:"true" validate:"required"` - // Type string `json:"type,omitempty" required:"true"` + Type string `json:"type,omitempty" required:"true"` DCacronym string `json:"DCacronym" required:"true" description:"Unique ID of the DC where it is the storage"` URL string `json:"URL"` @@ -137,3 +140,16 @@ func GetMultipleStorage(IDs []string) (object *[]StorageModel, err error) { return object, err } + +func (obj StorageModel) AddUserInput(inputs map[string]interface{} ){ + // So far only a few input to handle so a switch with a case for each type of attribute + // is enough, to prevent too much complexity + for key, value := range inputs { + switch strings.ToLower(key) { + case "URL": + obj.URL = value.(string) + default: + logs.Alert(fmt.Printf("%s is not an attribute of storage componants", key)) + } + } +} \ No newline at end of file