change selectedFileID parameter of component config to array of file ids (fileIDs) #37

This commit is contained in:
Sonja Happ 2020-07-06 15:31:51 +02:00
parent a2f3941951
commit 81c870528d
8 changed files with 58 additions and 44 deletions

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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})

View file

@ -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