mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Add array of SignalIDs to widget data model
This commit is contained in:
parent
dd0b9fe572
commit
9539c42e0b
6 changed files with 22 additions and 1 deletions
|
@ -22,6 +22,7 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/lib/pq"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm/dialects/postgres"
|
||||
|
@ -175,6 +176,8 @@ type Widget struct {
|
|||
DashboardID uint `json:"dashboardID"`
|
||||
// Files that belong to widget (for example images)
|
||||
Files []File `json:"-" gorm:"foreignkey:WidgetID"`
|
||||
// IDs of signals that widget uses
|
||||
SignalIDs pq.Int64Array `json:"signalIDs" gorm:"type:integer[]"`
|
||||
}
|
||||
|
||||
// File data model
|
||||
|
|
|
@ -212,6 +212,7 @@ var WidgetA = Widget{
|
|||
Z: 200,
|
||||
IsLocked: false,
|
||||
CustomProperties: postgres.Jsonb{customPropertiesLabel},
|
||||
SignalIDs: []int64{1},
|
||||
}
|
||||
|
||||
var WidgetB = Widget{
|
||||
|
@ -226,6 +227,7 @@ var WidgetB = Widget{
|
|||
Z: 0,
|
||||
IsLocked: false,
|
||||
CustomProperties: postgres.Jsonb{customPropertiesSlider},
|
||||
SignalIDs: []int64{1},
|
||||
}
|
||||
|
||||
var WidgetC = Widget{
|
||||
|
@ -240,6 +242,7 @@ var WidgetC = Widget{
|
|||
Z: 0,
|
||||
IsLocked: false,
|
||||
CustomProperties: postgres.Jsonb{customPropertiesBox},
|
||||
SignalIDs: []int64{3},
|
||||
}
|
||||
|
||||
var WidgetD = Widget{
|
||||
|
@ -253,7 +256,8 @@ var WidgetD = Widget{
|
|||
Y: 50,
|
||||
Z: 0,
|
||||
IsLocked: false,
|
||||
CustomProperties: postgres.Jsonb{customPropertiesBox},
|
||||
CustomProperties: postgres.Jsonb{customPropertiesCustomActions},
|
||||
SignalIDs: []int64{2},
|
||||
}
|
||||
|
||||
var WidgetE = Widget{
|
||||
|
@ -268,6 +272,7 @@ var WidgetE = Widget{
|
|||
Z: 0,
|
||||
IsLocked: false,
|
||||
CustomProperties: postgres.Jsonb{customPropertiesLamp},
|
||||
SignalIDs: []int64{4},
|
||||
}
|
||||
|
||||
func DBAddAdminUser(db *gorm.DB) error {
|
||||
|
|
1
go.mod
1
go.mod
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||
github.com/jinzhu/gorm v1.9.11
|
||||
github.com/leodido/go-urn v1.2.0 // indirect
|
||||
github.com/lib/pq v1.1.1
|
||||
github.com/nsf/jsondiff v0.0.0-20190712045011-8443391ee9b6
|
||||
github.com/prometheus/client_golang v1.2.1
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
|
|
|
@ -80,6 +80,7 @@ func (w *Widget) update(modifiedWidget Widget) error {
|
|||
"Z": modifiedWidget.Z,
|
||||
"IsLocked": modifiedWidget.IsLocked,
|
||||
"CustomProperties": modifiedWidget.CustomProperties,
|
||||
"SignalIDs": modifiedWidget.SignalIDs,
|
||||
}).Error
|
||||
|
||||
return err
|
||||
|
|
|
@ -53,6 +53,7 @@ type WidgetRequest struct {
|
|||
DashboardID uint `json:"dashboardID,omitempty"`
|
||||
IsLocked bool `json:"isLocked,omitempty"`
|
||||
CustomProperties postgres.Jsonb `json:"customProperties,omitempty"`
|
||||
SignalIDs []int64 `json:"signalIDs,omitempty"`
|
||||
}
|
||||
|
||||
type DashboardRequest struct {
|
||||
|
@ -153,6 +154,7 @@ func TestAddWidget(t *testing.T) {
|
|||
IsLocked: database.WidgetA.IsLocked,
|
||||
CustomProperties: database.WidgetA.CustomProperties,
|
||||
DashboardID: dashboardID,
|
||||
SignalIDs: database.WidgetA.SignalIDs,
|
||||
}
|
||||
|
||||
// authenticate as userB who has no access to scenario
|
||||
|
@ -253,6 +255,7 @@ func TestUpdateWidget(t *testing.T) {
|
|||
IsLocked: database.WidgetA.IsLocked,
|
||||
CustomProperties: database.WidgetA.CustomProperties,
|
||||
DashboardID: dashboardID,
|
||||
SignalIDs: database.WidgetA.SignalIDs,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/widgets", "POST", helper.KeyModels{"widget": newWidget})
|
||||
|
@ -271,6 +274,7 @@ func TestUpdateWidget(t *testing.T) {
|
|||
MinWidth: database.WidgetB.MinWidth,
|
||||
MinHeight: database.WidgetB.MinHeight,
|
||||
CustomProperties: database.WidgetA.CustomProperties,
|
||||
SignalIDs: database.WidgetB.SignalIDs,
|
||||
}
|
||||
|
||||
// authenticate as userB who has no access to scenario
|
||||
|
@ -363,6 +367,7 @@ func TestDeleteWidget(t *testing.T) {
|
|||
IsLocked: database.WidgetA.IsLocked,
|
||||
CustomProperties: database.WidgetA.CustomProperties,
|
||||
DashboardID: dashboardID,
|
||||
SignalIDs: database.WidgetA.SignalIDs,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/widgets", "POST", helper.KeyModels{"widget": newWidget})
|
||||
|
@ -461,6 +466,7 @@ func TestGetAllWidgetsOfDashboard(t *testing.T) {
|
|||
IsLocked: database.WidgetA.IsLocked,
|
||||
CustomProperties: database.WidgetA.CustomProperties,
|
||||
DashboardID: dashboardID,
|
||||
SignalIDs: database.WidgetA.SignalIDs,
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/widgets", "POST", helper.KeyModels{"widget": newWidgetA})
|
||||
|
@ -480,6 +486,7 @@ func TestGetAllWidgetsOfDashboard(t *testing.T) {
|
|||
IsLocked: database.WidgetB.IsLocked,
|
||||
CustomProperties: database.WidgetB.CustomProperties,
|
||||
DashboardID: dashboardID,
|
||||
SignalIDs: database.WidgetB.SignalIDs,
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/widgets", "POST", helper.KeyModels{"widget": newWidgetB})
|
||||
|
|
|
@ -43,6 +43,7 @@ type validNewWidget struct {
|
|||
DashboardID uint `form:"dashboardID" validate:"required"`
|
||||
IsLocked bool `form:"isLocked" validate:"omitempty"`
|
||||
CustomProperties postgres.Jsonb `form:"customProperties" validate:"omitempty"`
|
||||
SignalIDs []int64 `form:"signalIDs" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type validUpdatedWidget struct {
|
||||
|
@ -57,6 +58,7 @@ type validUpdatedWidget struct {
|
|||
Z int `form:"z" validate:"omitempty"`
|
||||
IsLocked bool `form:"isLocked" validate:"omitempty"`
|
||||
CustomProperties postgres.Jsonb `form:"customProperties" validate:"omitempty"`
|
||||
SignalIDs []int64 `form:"signalIDs" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type addWidgetRequest struct {
|
||||
|
@ -94,6 +96,7 @@ func (r *addWidgetRequest) createWidget() Widget {
|
|||
s.IsLocked = r.Widget.IsLocked
|
||||
s.CustomProperties = r.Widget.CustomProperties
|
||||
s.DashboardID = r.Widget.DashboardID
|
||||
s.SignalIDs = r.Widget.SignalIDs
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -114,6 +117,7 @@ func (r *updateWidgetRequest) updatedWidget(oldWidget Widget) Widget {
|
|||
s.Y = r.Widget.Y
|
||||
s.Z = r.Widget.Z
|
||||
s.IsLocked = r.Widget.IsLocked
|
||||
s.SignalIDs = r.Widget.SignalIDs
|
||||
|
||||
// only update custom props if not empty
|
||||
var emptyJson postgres.Jsonb
|
||||
|
|
Loading…
Add table
Reference in a new issue