diff --git a/database/models.go b/database/models.go index 479fe0f..8d1f36a 100644 --- a/database/models.go +++ b/database/models.go @@ -92,8 +92,8 @@ type ComponentConfiguration struct { OutputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"` // Mapping of input signals of the Component Configuration, order of signals is important InputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"` - // Currently selected FileID - SelectedFileID int `json:"selectedFileID" gorm:"default:0"` + // Array of file IDs used by the component configuration + FileIDs pq.Int64Array `json:"fileIDs" gorm:"type:integer[]"` } // Signal data model diff --git a/doc/api/docs.go b/doc/api/docs.go index 3fbbc88..b9b3711 100644 --- a/doc/api/docs.go +++ b/doc/api/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-06-26 10:15:00.429442173 +0200 CEST m=+0.087249443 +// 2020-07-06 15:29:44.957174619 +0200 CEST m=+0.089303074 package docs @@ -2879,6 +2879,12 @@ var doc = `{ "StartParameters" ], "properties": { + "FileIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "ICID": { "type": "integer" }, @@ -2888,9 +2894,6 @@ var doc = `{ "ScenarioID": { "type": "integer" }, - "SelectedFileID": { - "type": "integer" - }, "StartParameters": { "type": "string" } @@ -2899,15 +2902,18 @@ var doc = `{ "component_configuration.validUpdatedConfig": { "type": "object", "properties": { + "FileIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "ICID": { "type": "integer" }, "Name": { "type": "string" }, - "SelectedFileID": { - "type": "integer" - }, "StartParameters": { "type": "string" } @@ -2970,6 +2976,10 @@ var doc = `{ "database.ComponentConfiguration": { "type": "object", "properties": { + "fileIDs": { + "description": "Array of file IDs used by the component configuration", + "type": "string" + }, "icID": { "description": "ID of IC associated with Component Configuration", "type": "integer" @@ -2993,10 +3003,6 @@ var doc = `{ "description": "ID of Scenario to which Component Configuration belongs", "type": "integer" }, - "selectedFileID": { - "description": "Currently selected FileID", - "type": "integer" - }, "startParameters": { "description": "Start parameters of Component Configuration as JSON", "type": "string" diff --git a/doc/api/swagger.json b/doc/api/swagger.json index 7166f51..1575bce 100644 --- a/doc/api/swagger.json +++ b/doc/api/swagger.json @@ -2862,6 +2862,12 @@ "StartParameters" ], "properties": { + "FileIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "ICID": { "type": "integer" }, @@ -2871,9 +2877,6 @@ "ScenarioID": { "type": "integer" }, - "SelectedFileID": { - "type": "integer" - }, "StartParameters": { "type": "string" } @@ -2882,15 +2885,18 @@ "component_configuration.validUpdatedConfig": { "type": "object", "properties": { + "FileIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "ICID": { "type": "integer" }, "Name": { "type": "string" }, - "SelectedFileID": { - "type": "integer" - }, "StartParameters": { "type": "string" } @@ -2953,6 +2959,10 @@ "database.ComponentConfiguration": { "type": "object", "properties": { + "fileIDs": { + "description": "Array of file IDs used by the component configuration", + "type": "string" + }, "icID": { "description": "ID of IC associated with Component Configuration", "type": "integer" @@ -2976,10 +2986,6 @@ "description": "ID of Scenario to which Component Configuration belongs", "type": "integer" }, - "selectedFileID": { - "description": "Currently selected FileID", - "type": "integer" - }, "startParameters": { "description": "Start parameters of Component Configuration as JSON", "type": "string" diff --git a/doc/api/swagger.yaml b/doc/api/swagger.yaml index 96ebd40..dd10877 100644 --- a/doc/api/swagger.yaml +++ b/doc/api/swagger.yaml @@ -14,14 +14,16 @@ definitions: type: object component_configuration.validNewConfig: properties: + FileIDs: + items: + type: integer + type: array ICID: type: integer Name: type: string ScenarioID: type: integer - SelectedFileID: - type: integer StartParameters: type: string required: @@ -32,12 +34,14 @@ definitions: type: object component_configuration.validUpdatedConfig: properties: + FileIDs: + items: + type: integer + type: array ICID: type: integer Name: type: string - SelectedFileID: - type: integer StartParameters: type: string type: object @@ -79,6 +83,9 @@ definitions: type: object database.ComponentConfiguration: properties: + fileIDs: + description: Array of file IDs used by the component configuration + type: string icID: description: ID of IC associated with Component Configuration type: integer @@ -96,9 +103,6 @@ definitions: scenarioID: description: ID of Scenario to which Component Configuration belongs type: integer - selectedFileID: - description: Currently selected FileID - type: integer startParameters: description: Start parameters of Component Configuration as JSON type: string diff --git a/helper/test_data.go b/helper/test_data.go index 89886fe..2128617 100644 --- a/helper/test_data.go +++ b/helper/test_data.go @@ -139,13 +139,13 @@ var ScenarioB = database.Scenario{ var ConfigA = database.ComponentConfiguration{ Name: "Example for Signal generator", StartParameters: postgres.Jsonb{startParametersA}, - SelectedFileID: -1, + FileIDs: []int64{}, } var ConfigB = database.ComponentConfiguration{ Name: "VILLASnode gateway X", StartParameters: postgres.Jsonb{startParametersB}, - SelectedFileID: -1, + FileIDs: []int64{}, } // Signals diff --git a/routes/component-configuration/config_methods.go b/routes/component-configuration/config_methods.go index 7be2d32..c48473f 100644 --- a/routes/component-configuration/config_methods.go +++ b/routes/component-configuration/config_methods.go @@ -106,7 +106,7 @@ func (m *ComponentConfiguration) Update(modifiedConfig ComponentConfiguration) e "Name": modifiedConfig.Name, "StartParameters": modifiedConfig.StartParameters, "ICID": modifiedConfig.ICID, - "SelectedFileID": modifiedConfig.SelectedFileID, + "FileIDs": modifiedConfig.FileIDs, }).Error return err diff --git a/routes/component-configuration/config_test.go b/routes/component-configuration/config_test.go index 2766567..e283f99 100644 --- a/routes/component-configuration/config_test.go +++ b/routes/component-configuration/config_test.go @@ -45,7 +45,7 @@ type ConfigRequest struct { ScenarioID uint `json:"scenarioID,omitempty"` ICID uint `json:"icID,omitempty"` StartParameters postgres.Jsonb `json:"startParameters,omitempty"` - SelectedFileID int `json:"selectedFileID,omitempty"` + FileIDs []int64 `json:"fileIDs,omitempty"` } type ICRequest struct { @@ -165,7 +165,7 @@ func TestAddConfig(t *testing.T) { ScenarioID: scenarioID, ICID: ICID, StartParameters: helper.ConfigA.StartParameters, - SelectedFileID: helper.ConfigA.SelectedFileID, + FileIDs: helper.ConfigA.FileIDs, } // authenticate as normal userB who has no access to new scenario @@ -267,7 +267,7 @@ func TestUpdateConfig(t *testing.T) { ScenarioID: scenarioID, ICID: ICID, StartParameters: helper.ConfigA.StartParameters, - SelectedFileID: helper.ConfigA.SelectedFileID, + FileIDs: helper.ConfigA.FileIDs, } code, resp, err := helper.TestEndpoint(router, token, base_api_configs, "POST", helper.KeyModels{"config": newConfig}) @@ -373,7 +373,7 @@ func TestDeleteConfig(t *testing.T) { ScenarioID: scenarioID, ICID: ICID, StartParameters: helper.ConfigA.StartParameters, - SelectedFileID: helper.ConfigA.SelectedFileID, + FileIDs: helper.ConfigA.FileIDs, } // authenticate as normal user @@ -452,7 +452,7 @@ func TestGetAllConfigsOfScenario(t *testing.T) { ScenarioID: scenarioID, ICID: ICID, StartParameters: helper.ConfigA.StartParameters, - SelectedFileID: helper.ConfigA.SelectedFileID, + FileIDs: helper.ConfigA.FileIDs, } code, resp, err := helper.TestEndpoint(router, token, base_api_configs, "POST", helper.KeyModels{"config": newConfig}) diff --git a/routes/component-configuration/config_validators.go b/routes/component-configuration/config_validators.go index 6bd9c7c..660de7b 100644 --- a/routes/component-configuration/config_validators.go +++ b/routes/component-configuration/config_validators.go @@ -35,14 +35,14 @@ type validNewConfig struct { ScenarioID uint `form:"ScenarioID" validate:"required"` ICID uint `form:"ICID" validate:"required"` StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"` - SelectedFileID int `form:"SelectedFileID" validate:"omitempty"` + FileIDs []int64 `form:"FileIDs" validate:"omitempty"` } type validUpdatedConfig struct { Name string `form:"Name" validate:"omitempty"` ICID uint `form:"ICID" validate:"omitempty"` StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"` - SelectedFileID int `form:"SelectedFileID" validate:"omitempty"` + FileIDs []int64 `form:"FileIDs" validate:"omitempty"` } type addConfigRequest struct { @@ -72,7 +72,7 @@ func (r *addConfigRequest) createConfig() ComponentConfiguration { s.ScenarioID = r.Config.ScenarioID s.ICID = r.Config.ICID s.StartParameters = r.Config.StartParameters - s.SelectedFileID = r.Config.SelectedFileID + s.FileIDs = r.Config.FileIDs return s } @@ -89,9 +89,7 @@ func (r *updateConfigRequest) updateConfig(oldConfig ComponentConfiguration) Com s.ICID = r.Config.ICID } - if r.Config.SelectedFileID != 0 { - s.SelectedFileID = r.Config.SelectedFileID - } + s.FileIDs = r.Config.FileIDs // only update Params if not empty var emptyJson postgres.Jsonb