mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
change selectedFileID parameter of component config to array of file ids (fileIDs) #37
This commit is contained in:
parent
a2f3941951
commit
81c870528d
8 changed files with 58 additions and 44 deletions
|
@ -92,8 +92,8 @@ type ComponentConfiguration struct {
|
||||||
OutputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"`
|
OutputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"`
|
||||||
// Mapping of input signals of the Component Configuration, order of signals is important
|
// Mapping of input signals of the Component Configuration, order of signals is important
|
||||||
InputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"`
|
InputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"`
|
||||||
// Currently selected FileID
|
// Array of file IDs used by the component configuration
|
||||||
SelectedFileID int `json:"selectedFileID" gorm:"default:0"`
|
FileIDs pq.Int64Array `json:"fileIDs" gorm:"type:integer[]"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal data model
|
// Signal data model
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||||
// This file was generated by swaggo/swag at
|
// 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
|
package docs
|
||||||
|
|
||||||
|
@ -2879,6 +2879,12 @@ var doc = `{
|
||||||
"StartParameters"
|
"StartParameters"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"FileIDs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ICID": {
|
"ICID": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
@ -2888,9 +2894,6 @@ var doc = `{
|
||||||
"ScenarioID": {
|
"ScenarioID": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"SelectedFileID": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"StartParameters": {
|
"StartParameters": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
@ -2899,15 +2902,18 @@ var doc = `{
|
||||||
"component_configuration.validUpdatedConfig": {
|
"component_configuration.validUpdatedConfig": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"FileIDs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ICID": {
|
"ICID": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"Name": {
|
"Name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"SelectedFileID": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"StartParameters": {
|
"StartParameters": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
@ -2970,6 +2976,10 @@ var doc = `{
|
||||||
"database.ComponentConfiguration": {
|
"database.ComponentConfiguration": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"fileIDs": {
|
||||||
|
"description": "Array of file IDs used by the component configuration",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"icID": {
|
"icID": {
|
||||||
"description": "ID of IC associated with Component Configuration",
|
"description": "ID of IC associated with Component Configuration",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
@ -2993,10 +3003,6 @@ var doc = `{
|
||||||
"description": "ID of Scenario to which Component Configuration belongs",
|
"description": "ID of Scenario to which Component Configuration belongs",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"selectedFileID": {
|
|
||||||
"description": "Currently selected FileID",
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"startParameters": {
|
"startParameters": {
|
||||||
"description": "Start parameters of Component Configuration as JSON",
|
"description": "Start parameters of Component Configuration as JSON",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
|
@ -2862,6 +2862,12 @@
|
||||||
"StartParameters"
|
"StartParameters"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"FileIDs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ICID": {
|
"ICID": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
@ -2871,9 +2877,6 @@
|
||||||
"ScenarioID": {
|
"ScenarioID": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"SelectedFileID": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"StartParameters": {
|
"StartParameters": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
@ -2882,15 +2885,18 @@
|
||||||
"component_configuration.validUpdatedConfig": {
|
"component_configuration.validUpdatedConfig": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"FileIDs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ICID": {
|
"ICID": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"Name": {
|
"Name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"SelectedFileID": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"StartParameters": {
|
"StartParameters": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
@ -2953,6 +2959,10 @@
|
||||||
"database.ComponentConfiguration": {
|
"database.ComponentConfiguration": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"fileIDs": {
|
||||||
|
"description": "Array of file IDs used by the component configuration",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"icID": {
|
"icID": {
|
||||||
"description": "ID of IC associated with Component Configuration",
|
"description": "ID of IC associated with Component Configuration",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
@ -2976,10 +2986,6 @@
|
||||||
"description": "ID of Scenario to which Component Configuration belongs",
|
"description": "ID of Scenario to which Component Configuration belongs",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"selectedFileID": {
|
|
||||||
"description": "Currently selected FileID",
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"startParameters": {
|
"startParameters": {
|
||||||
"description": "Start parameters of Component Configuration as JSON",
|
"description": "Start parameters of Component Configuration as JSON",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
|
@ -14,14 +14,16 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
component_configuration.validNewConfig:
|
component_configuration.validNewConfig:
|
||||||
properties:
|
properties:
|
||||||
|
FileIDs:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
ICID:
|
ICID:
|
||||||
type: integer
|
type: integer
|
||||||
Name:
|
Name:
|
||||||
type: string
|
type: string
|
||||||
ScenarioID:
|
ScenarioID:
|
||||||
type: integer
|
type: integer
|
||||||
SelectedFileID:
|
|
||||||
type: integer
|
|
||||||
StartParameters:
|
StartParameters:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
|
@ -32,12 +34,14 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
component_configuration.validUpdatedConfig:
|
component_configuration.validUpdatedConfig:
|
||||||
properties:
|
properties:
|
||||||
|
FileIDs:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
ICID:
|
ICID:
|
||||||
type: integer
|
type: integer
|
||||||
Name:
|
Name:
|
||||||
type: string
|
type: string
|
||||||
SelectedFileID:
|
|
||||||
type: integer
|
|
||||||
StartParameters:
|
StartParameters:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
@ -79,6 +83,9 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
database.ComponentConfiguration:
|
database.ComponentConfiguration:
|
||||||
properties:
|
properties:
|
||||||
|
fileIDs:
|
||||||
|
description: Array of file IDs used by the component configuration
|
||||||
|
type: string
|
||||||
icID:
|
icID:
|
||||||
description: ID of IC associated with Component Configuration
|
description: ID of IC associated with Component Configuration
|
||||||
type: integer
|
type: integer
|
||||||
|
@ -96,9 +103,6 @@ definitions:
|
||||||
scenarioID:
|
scenarioID:
|
||||||
description: ID of Scenario to which Component Configuration belongs
|
description: ID of Scenario to which Component Configuration belongs
|
||||||
type: integer
|
type: integer
|
||||||
selectedFileID:
|
|
||||||
description: Currently selected FileID
|
|
||||||
type: integer
|
|
||||||
startParameters:
|
startParameters:
|
||||||
description: Start parameters of Component Configuration as JSON
|
description: Start parameters of Component Configuration as JSON
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -139,13 +139,13 @@ var ScenarioB = database.Scenario{
|
||||||
var ConfigA = database.ComponentConfiguration{
|
var ConfigA = database.ComponentConfiguration{
|
||||||
Name: "Example for Signal generator",
|
Name: "Example for Signal generator",
|
||||||
StartParameters: postgres.Jsonb{startParametersA},
|
StartParameters: postgres.Jsonb{startParametersA},
|
||||||
SelectedFileID: -1,
|
FileIDs: []int64{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigB = database.ComponentConfiguration{
|
var ConfigB = database.ComponentConfiguration{
|
||||||
Name: "VILLASnode gateway X",
|
Name: "VILLASnode gateway X",
|
||||||
StartParameters: postgres.Jsonb{startParametersB},
|
StartParameters: postgres.Jsonb{startParametersB},
|
||||||
SelectedFileID: -1,
|
FileIDs: []int64{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (m *ComponentConfiguration) Update(modifiedConfig ComponentConfiguration) e
|
||||||
"Name": modifiedConfig.Name,
|
"Name": modifiedConfig.Name,
|
||||||
"StartParameters": modifiedConfig.StartParameters,
|
"StartParameters": modifiedConfig.StartParameters,
|
||||||
"ICID": modifiedConfig.ICID,
|
"ICID": modifiedConfig.ICID,
|
||||||
"SelectedFileID": modifiedConfig.SelectedFileID,
|
"FileIDs": modifiedConfig.FileIDs,
|
||||||
}).Error
|
}).Error
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -45,7 +45,7 @@ type ConfigRequest struct {
|
||||||
ScenarioID uint `json:"scenarioID,omitempty"`
|
ScenarioID uint `json:"scenarioID,omitempty"`
|
||||||
ICID uint `json:"icID,omitempty"`
|
ICID uint `json:"icID,omitempty"`
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
SelectedFileID int `json:"selectedFileID,omitempty"`
|
FileIDs []int64 `json:"fileIDs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICRequest struct {
|
type ICRequest struct {
|
||||||
|
@ -165,7 +165,7 @@ func TestAddConfig(t *testing.T) {
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
ICID: ICID,
|
ICID: ICID,
|
||||||
StartParameters: helper.ConfigA.StartParameters,
|
StartParameters: helper.ConfigA.StartParameters,
|
||||||
SelectedFileID: helper.ConfigA.SelectedFileID,
|
FileIDs: helper.ConfigA.FileIDs,
|
||||||
}
|
}
|
||||||
|
|
||||||
// authenticate as normal userB who has no access to new scenario
|
// authenticate as normal userB who has no access to new scenario
|
||||||
|
@ -267,7 +267,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
ICID: ICID,
|
ICID: ICID,
|
||||||
StartParameters: helper.ConfigA.StartParameters,
|
StartParameters: helper.ConfigA.StartParameters,
|
||||||
SelectedFileID: helper.ConfigA.SelectedFileID,
|
FileIDs: helper.ConfigA.FileIDs,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
base_api_configs, "POST", helper.KeyModels{"config": newConfig})
|
base_api_configs, "POST", helper.KeyModels{"config": newConfig})
|
||||||
|
@ -373,7 +373,7 @@ func TestDeleteConfig(t *testing.T) {
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
ICID: ICID,
|
ICID: ICID,
|
||||||
StartParameters: helper.ConfigA.StartParameters,
|
StartParameters: helper.ConfigA.StartParameters,
|
||||||
SelectedFileID: helper.ConfigA.SelectedFileID,
|
FileIDs: helper.ConfigA.FileIDs,
|
||||||
}
|
}
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
|
@ -452,7 +452,7 @@ func TestGetAllConfigsOfScenario(t *testing.T) {
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
ICID: ICID,
|
ICID: ICID,
|
||||||
StartParameters: helper.ConfigA.StartParameters,
|
StartParameters: helper.ConfigA.StartParameters,
|
||||||
SelectedFileID: helper.ConfigA.SelectedFileID,
|
FileIDs: helper.ConfigA.FileIDs,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
base_api_configs, "POST", helper.KeyModels{"config": newConfig})
|
base_api_configs, "POST", helper.KeyModels{"config": newConfig})
|
||||||
|
|
|
@ -35,14 +35,14 @@ type validNewConfig struct {
|
||||||
ScenarioID uint `form:"ScenarioID" validate:"required"`
|
ScenarioID uint `form:"ScenarioID" validate:"required"`
|
||||||
ICID uint `form:"ICID" validate:"required"`
|
ICID uint `form:"ICID" validate:"required"`
|
||||||
StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"`
|
StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"`
|
||||||
SelectedFileID int `form:"SelectedFileID" validate:"omitempty"`
|
FileIDs []int64 `form:"FileIDs" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type validUpdatedConfig struct {
|
type validUpdatedConfig struct {
|
||||||
Name string `form:"Name" validate:"omitempty"`
|
Name string `form:"Name" validate:"omitempty"`
|
||||||
ICID uint `form:"ICID" validate:"omitempty"`
|
ICID uint `form:"ICID" validate:"omitempty"`
|
||||||
StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"`
|
StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"`
|
||||||
SelectedFileID int `form:"SelectedFileID" validate:"omitempty"`
|
FileIDs []int64 `form:"FileIDs" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type addConfigRequest struct {
|
type addConfigRequest struct {
|
||||||
|
@ -72,7 +72,7 @@ func (r *addConfigRequest) createConfig() ComponentConfiguration {
|
||||||
s.ScenarioID = r.Config.ScenarioID
|
s.ScenarioID = r.Config.ScenarioID
|
||||||
s.ICID = r.Config.ICID
|
s.ICID = r.Config.ICID
|
||||||
s.StartParameters = r.Config.StartParameters
|
s.StartParameters = r.Config.StartParameters
|
||||||
s.SelectedFileID = r.Config.SelectedFileID
|
s.FileIDs = r.Config.FileIDs
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -89,9 +89,7 @@ func (r *updateConfigRequest) updateConfig(oldConfig ComponentConfiguration) Com
|
||||||
s.ICID = r.Config.ICID
|
s.ICID = r.Config.ICID
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Config.SelectedFileID != 0 {
|
s.FileIDs = r.Config.FileIDs
|
||||||
s.SelectedFileID = r.Config.SelectedFileID
|
|
||||||
}
|
|
||||||
|
|
||||||
// only update Params if not empty
|
// only update Params if not empty
|
||||||
var emptyJson postgres.Jsonb
|
var emptyJson postgres.Jsonb
|
||||||
|
|
Loading…
Add table
Reference in a new issue