mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
allow signal indices to start at 0 instead of 1
This commit is contained in:
parent
5cd136c558
commit
a4947a53e9
4 changed files with 29 additions and 32 deletions
|
@ -353,43 +353,43 @@
|
|||
"name": "outSignal_A",
|
||||
"direction": "out",
|
||||
"unit": "V",
|
||||
"index": 1
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"name": "outSignal_B",
|
||||
"direction": "out",
|
||||
"unit": "V",
|
||||
"index": 2
|
||||
"index": 1
|
||||
},
|
||||
{
|
||||
"name": "outSignal_C",
|
||||
"direction": "out",
|
||||
"unit": "---",
|
||||
"index": 3
|
||||
"index": 2
|
||||
},
|
||||
{
|
||||
"name": "outSignal_D",
|
||||
"direction": "out",
|
||||
"unit": "---",
|
||||
"index": 4
|
||||
"index": 3
|
||||
},
|
||||
{
|
||||
"name": "outSignal_E",
|
||||
"direction": "out",
|
||||
"unit": "---",
|
||||
"index": 5
|
||||
"index": 4
|
||||
},
|
||||
{
|
||||
"name": "inSignal_A",
|
||||
"direction": "in",
|
||||
"unit": "---",
|
||||
"index": 1
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"name": "inSignal_B",
|
||||
"direction": "in",
|
||||
"unit": "---",
|
||||
"index": 2
|
||||
"index": 1
|
||||
}
|
||||
|
||||
]
|
||||
|
|
|
@ -44,7 +44,7 @@ var router *gin.Engine
|
|||
type SignalRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
Index uint `json:"index,omitempty"`
|
||||
Index *uint `json:"index,omitempty"`
|
||||
Direction string `json:"direction,omitempty"`
|
||||
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
||||
ConfigID uint `json:"configID,omitempty"`
|
||||
|
@ -76,11 +76,14 @@ type ScenarioRequest struct {
|
|||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||
}
|
||||
|
||||
var signalIndex0 uint = 0
|
||||
var signalIndex1 uint = 1
|
||||
|
||||
var newSignal1 = SignalRequest{
|
||||
Name: "outSignal_A",
|
||||
Unit: "V",
|
||||
Direction: "out",
|
||||
Index: 1,
|
||||
Index: &signalIndex0,
|
||||
}
|
||||
|
||||
func newFalse() *bool {
|
||||
|
@ -226,6 +229,7 @@ func TestAddSignal(t *testing.T) {
|
|||
"/api/v2/signals", "POST", helper.KeyModels{"signal": newSignal1})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
fmt.Println(resp)
|
||||
|
||||
// Compare POST's response with the newSignal
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"signal": newSignal1})
|
||||
|
@ -296,7 +300,7 @@ func TestUpdateSignal(t *testing.T) {
|
|||
updatedSignal := SignalRequest{
|
||||
Name: "outSignal_B",
|
||||
Unit: "A",
|
||||
Index: 1,
|
||||
Index: &signalIndex1,
|
||||
}
|
||||
|
||||
// authenticate as normal userB who has no access to new scenario
|
||||
|
@ -379,7 +383,7 @@ func TestDeleteSignal(t *testing.T) {
|
|||
Name: "insignalA",
|
||||
Unit: "s",
|
||||
Direction: "in",
|
||||
Index: 1,
|
||||
Index: &signalIndex0,
|
||||
ConfigID: configID,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
|
@ -470,7 +474,7 @@ func TestGetAllInputSignalsOfConfig(t *testing.T) {
|
|||
Name: "inA",
|
||||
Unit: "s",
|
||||
Direction: "in",
|
||||
Index: 1,
|
||||
Index: &signalIndex0,
|
||||
ConfigID: configID,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
|
@ -483,7 +487,7 @@ func TestGetAllInputSignalsOfConfig(t *testing.T) {
|
|||
Name: "inB",
|
||||
Unit: "m",
|
||||
Direction: "in",
|
||||
Index: 2,
|
||||
Index: &signalIndex1,
|
||||
ConfigID: configID,
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
|
@ -503,7 +507,7 @@ func TestGetAllInputSignalsOfConfig(t *testing.T) {
|
|||
Name: "outB",
|
||||
Unit: "A",
|
||||
Direction: "out",
|
||||
Index: 1,
|
||||
Index: &signalIndex1,
|
||||
ConfigID: configID,
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
|
|
|
@ -30,7 +30,7 @@ var validate *validator.Validate
|
|||
type validNewSignal struct {
|
||||
Name string `form:"Name" validate:"required"`
|
||||
Unit string `form:"unit" validate:"omitempty"`
|
||||
Index uint `form:"index" validate:"required"`
|
||||
Index *uint `form:"index" validate:"required"`
|
||||
Direction string `form:"direction" validate:"required,oneof=in out"`
|
||||
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
|
||||
ConfigID uint `form:"configID" validate:"required"`
|
||||
|
@ -39,7 +39,7 @@ type validNewSignal struct {
|
|||
type validUpdatedSignal struct {
|
||||
Name string `form:"Name" validate:"omitempty"`
|
||||
Unit string `form:"unit" validate:"omitempty"`
|
||||
Index uint `form:"index" validate:"omitempty"`
|
||||
Index *uint `form:"index" validate:"omitempty"`
|
||||
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func (r *addSignalRequest) createSignal() Signal {
|
|||
|
||||
s.Name = r.Signal.Name
|
||||
s.Unit = r.Signal.Unit
|
||||
s.Index = r.Signal.Index
|
||||
s.Index = *r.Signal.Index
|
||||
s.Direction = r.Signal.Direction
|
||||
s.ScalingFactor = r.Signal.ScalingFactor
|
||||
s.ConfigID = r.Signal.ConfigID
|
||||
|
@ -80,18 +80,9 @@ func (r *updateSignalRequest) updatedSignal(oldSignal Signal) Signal {
|
|||
// Use the old Signal as a basis for the updated Signal `s`
|
||||
s := oldSignal
|
||||
|
||||
if r.Signal.Name != "" {
|
||||
s.Name = r.Signal.Name
|
||||
}
|
||||
|
||||
if r.Signal.Index != 0 {
|
||||
// TODO this implies that we start indexing at 1
|
||||
s.Index = r.Signal.Index
|
||||
}
|
||||
|
||||
if r.Signal.Unit != "" {
|
||||
s.Unit = r.Signal.Unit
|
||||
}
|
||||
s.Name = r.Signal.Name
|
||||
s.Index = *r.Signal.Index
|
||||
s.Unit = r.Signal.Unit
|
||||
|
||||
if r.Signal.ScalingFactor != 0 {
|
||||
// scaling factor of 0 is not allowed
|
||||
|
|
|
@ -1586,17 +1586,19 @@ func addSignals(token string) error {
|
|||
type SignalRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
Index uint `json:"index,omitempty"`
|
||||
Index *uint `json:"index,omitempty"`
|
||||
Direction string `json:"direction,omitempty"`
|
||||
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
||||
ConfigID uint `json:"configID,omitempty"`
|
||||
}
|
||||
|
||||
var signalIndex0 uint = 0
|
||||
var signalIndex1 uint = 1
|
||||
var newSignalOut = SignalRequest{
|
||||
Name: "outSignal_A",
|
||||
Unit: "V",
|
||||
Direction: "out",
|
||||
Index: 1,
|
||||
Index: &signalIndex0,
|
||||
ConfigID: 1,
|
||||
}
|
||||
|
||||
|
@ -1604,7 +1606,7 @@ func addSignals(token string) error {
|
|||
Name: "inSignal_A",
|
||||
Unit: "V",
|
||||
Direction: "in",
|
||||
Index: 2,
|
||||
Index: &signalIndex1,
|
||||
ConfigID: 1,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue