Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASweb-backend-go
Commits
93bdd15e
Commit
93bdd15e
authored
Jun 26, 2020
by
Sonja Happ
Browse files
add scalingFactor parameter to Signal data model
#33
parent
aea28c71
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
database/models.go
View file @
93bdd15e
...
...
@@ -107,6 +107,8 @@ type Signal struct {
Index
uint
`json:"index"`
// Direction of the signal (in or out)
Direction
string
`json:"direction"`
// Scaling factor for the signal raw value (defaults to 1.0)
ScalingFactor
float32
`json:"scalingFactor" gorm:"default:1"`
// ID of Component Configuration
ConfigID
uint
`json:"configID"`
}
...
...
doc/api/docs.go
View file @
93bdd15e
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-06-26
09:52:23.901926224
+0200 CEST m=+0.0
7
724
5770
// 2020-06-26
10:15:00.429442173
+0200 CEST m=+0.0
8
724
9443
package
docs
...
...
@@ -3149,6 +3149,10 @@ var doc = `{
"description": "Name of Signal",
"type": "string"
},
"scalingFactor": {
"description": "Scaling factor for the signal raw value (defaults to 1.0)",
"type": "number"
},
"unit": {
"description": "Unit of Signal",
"type": "string"
...
...
@@ -3600,6 +3604,9 @@ var doc = `{
"Name": {
"type": "string"
},
"ScalingFactor": {
"type": "number"
},
"Unit": {
"type": "string"
}
...
...
@@ -3614,6 +3621,9 @@ var doc = `{
"Name": {
"type": "string"
},
"ScalingFactor": {
"type": "number"
},
"Unit": {
"type": "string"
}
...
...
doc/api/swagger.json
View file @
93bdd15e
...
...
@@ -3132,6 +3132,10 @@
"description"
:
"Name of Signal"
,
"type"
:
"string"
},
"scalingFactor"
:
{
"description"
:
"Scaling factor for the signal raw value (defaults to 1.0)"
,
"type"
:
"number"
},
"unit"
:
{
"description"
:
"Unit of Signal"
,
"type"
:
"string"
...
...
@@ -3583,6 +3587,9 @@
"Name"
:
{
"type"
:
"string"
},
"ScalingFactor"
:
{
"type"
:
"number"
},
"Unit"
:
{
"type"
:
"string"
}
...
...
@@ -3597,6 +3604,9 @@
"Name"
:
{
"type"
:
"string"
},
"ScalingFactor"
:
{
"type"
:
"number"
},
"Unit"
:
{
"type"
:
"string"
}
...
...
doc/api/swagger.yaml
View file @
93bdd15e
...
...
@@ -208,6 +208,9 @@ definitions:
name
:
description
:
Name of Signal
type
:
string
scalingFactor
:
description
:
Scaling factor for the signal raw value (defaults to 1.0)
type
:
number
unit
:
description
:
Unit of Signal
type
:
string
...
...
@@ -508,6 +511,8 @@ definitions:
type
:
integer
Name
:
type
:
string
ScalingFactor
:
type
:
number
Unit
:
type
:
string
required
:
...
...
@@ -522,6 +527,8 @@ definitions:
type
:
integer
Name
:
type
:
string
ScalingFactor
:
type
:
number
Unit
:
type
:
string
type
:
object
...
...
routes/signal/signal_methods.go
View file @
93bdd15e
...
...
@@ -87,9 +87,10 @@ func (s *Signal) update(modifiedSignal Signal) error {
db
:=
database
.
GetDB
()
err
:=
db
.
Model
(
s
)
.
Updates
(
map
[
string
]
interface
{}{
"Name"
:
modifiedSignal
.
Name
,
"Unit"
:
modifiedSignal
.
Unit
,
"Index"
:
modifiedSignal
.
Index
,
"Name"
:
modifiedSignal
.
Name
,
"Unit"
:
modifiedSignal
.
Unit
,
"Index"
:
modifiedSignal
.
Index
,
"ScalingFactor"
:
modifiedSignal
.
ScalingFactor
,
})
.
Error
return
err
...
...
routes/signal/signal_test.go
View file @
93bdd15e
...
...
@@ -40,11 +40,12 @@ import (
var
router
*
gin
.
Engine
type
SignalRequest
struct
{
Name
string
`json:"name,omitempty"`
Unit
string
`json:"unit,omitempty"`
Index
uint
`json:"index,omitempty"`
Direction
string
`json:"direction,omitempty"`
ConfigID
uint
`json:"configID,omitempty"`
Name
string
`json:"name,omitempty"`
Unit
string
`json:"unit,omitempty"`
Index
uint
`json:"index,omitempty"`
Direction
string
`json:"direction,omitempty"`
ScalingFactor
float32
`json:"scalingFactor,omitempty"`
ConfigID
uint
`json:"configID,omitempty"`
}
type
ConfigRequest
struct
{
...
...
routes/signal/signal_validators.go
View file @
93bdd15e
...
...
@@ -28,17 +28,19 @@ import (
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"`
Direction
string
`form:"direction" validate:"required,oneof=in out"`
ConfigID
uint
`form:"configID" validate:"required"`
Name
string
`form:"Name" validate:"required"`
Unit
string
`form:"unit" validate:"omitempty"`
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"`
}
type
validUpdatedSignal
struct
{
Name
string
`form:"Name" validate:"omitempty"`
Unit
string
`form:"unit" validate:"omitempty"`
Index
uint
`form:"index" validate:"omitempty"`
Name
string
`form:"Name" validate:"omitempty"`
Unit
string
`form:"unit" validate:"omitempty"`
Index
uint
`form:"index" validate:"omitempty"`
ScalingFactor
float32
`form:"scalingFactor" validate:"omitempty"`
}
type
addSignalRequest
struct
{
...
...
@@ -68,6 +70,7 @@ func (r *addSignalRequest) createSignal() Signal {
s
.
Unit
=
r
.
Signal
.
Unit
s
.
Index
=
r
.
Signal
.
Index
s
.
Direction
=
r
.
Signal
.
Direction
s
.
ScalingFactor
=
r
.
Signal
.
ScalingFactor
s
.
ConfigID
=
r
.
Signal
.
ConfigID
return
s
...
...
@@ -90,5 +93,10 @@ func (r *updateSignalRequest) updatedSignal(oldSignal Signal) Signal {
s
.
Unit
=
r
.
Signal
.
Unit
}
if
r
.
Signal
.
ScalingFactor
!=
0
{
// scaling factor of 0 is not allowed
s
.
ScalingFactor
=
r
.
Signal
.
ScalingFactor
}
return
s
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment