mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
fix many to many relationship between users and simulations
This commit is contained in:
parent
6e84929ef9
commit
084d3ec8d8
1 changed files with 54 additions and 58 deletions
112
common/models.go
112
common/models.go
|
@ -7,94 +7,92 @@ import (
|
||||||
// User data model
|
// User data model
|
||||||
type User struct {
|
type User struct {
|
||||||
// ID of user
|
// ID of user
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// Username of user
|
// Username of user
|
||||||
Username string `gorm:"unique;not null"`
|
Username string `gorm:"unique;not null"`
|
||||||
// Password of user
|
// Password of user
|
||||||
Password string `gorm:"not null"`
|
Password string `gorm:"not null"`
|
||||||
// Mail of user
|
// Mail of user
|
||||||
Mail string `gorm:"default:''"`
|
Mail string `gorm:"default:''"`
|
||||||
// Role of user
|
// Role of user
|
||||||
Role string `gorm:"default:'user'"`
|
Role string `gorm:"default:'user'"`
|
||||||
// Simulations to which user has access
|
// Simulations to which user has access
|
||||||
Simulations []Simulation `gorm:"many2many:user_simulations"`
|
Simulations []*Simulation `gorm:"many2many:user_simulations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Simulation data model
|
// Simulation data model
|
||||||
type Simulation struct {
|
type Simulation struct {
|
||||||
// ID of simulation
|
// ID of simulation
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// Name of simulation
|
// Name of simulation
|
||||||
Name string `gorm:"not null"`
|
Name string `gorm:"not null"`
|
||||||
// Running state of simulation
|
// Running state of simulation
|
||||||
Running bool `gorm:"default:false"`
|
Running bool `gorm:"default:false"`
|
||||||
// Start parameters of simulation as JSON string
|
// Start parameters of simulation as JSON string
|
||||||
StartParameters string
|
StartParameters string
|
||||||
// Users that have access to the simulation
|
// Users that have access to the simulation
|
||||||
Users []User `gorm:"not null;many2many:user_simulations"`
|
Users []*User `gorm:"not null;many2many:user_simulations"`
|
||||||
// Models that belong to the simulation
|
// Models that belong to the simulation
|
||||||
Models []Model `gorm:"foreignkey:SimulationID"`
|
Models []Model `gorm:"foreignkey:SimulationID"`
|
||||||
// Visualizations that belong to the simulation
|
// Visualizations that belong to the simulation
|
||||||
Visualizations []Visualization `gorm:"foreignkey:SimulationID"`
|
Visualizations []Visualization `gorm:"foreignkey:SimulationID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model data model
|
// Model data model
|
||||||
type Model struct {
|
type Model struct {
|
||||||
// ID of model
|
// ID of model
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// Name of model
|
// Name of model
|
||||||
Name string `gorm:"not null"`
|
Name string `gorm:"not null"`
|
||||||
// Number of output signals
|
// Number of output signals
|
||||||
OutputLength int `gorm:"default:1"`
|
OutputLength int `gorm:"default:1"`
|
||||||
// Number of input signals
|
// Number of input signals
|
||||||
InputLength int `gorm:"default:1"`
|
InputLength int `gorm:"default:1"`
|
||||||
// Start parameters of model as JSON string
|
// Start parameters of model as JSON string
|
||||||
StartParameters string
|
StartParameters string
|
||||||
// ID of simulation to which model belongs
|
// ID of simulation to which model belongs
|
||||||
SimulationID uint
|
SimulationID uint
|
||||||
// Simulator associated with model
|
// Simulator associated with model
|
||||||
Simulator Simulator
|
Simulator Simulator
|
||||||
// ID of simulator associated with model
|
// ID of simulator associated with model
|
||||||
SimulatorID uint
|
SimulatorID uint
|
||||||
// Mapping of output signals of the model, order of signals is important
|
// Mapping of output signals of the model, order of signals is important
|
||||||
OutputMapping []Signal
|
OutputMapping []Signal
|
||||||
// Mapping of input signals of the model, order of signals is important
|
// Mapping of input signals of the model, order of signals is important
|
||||||
InputMapping []Signal
|
InputMapping []Signal
|
||||||
// Files of model (can be CIM and other model file formats)
|
// Files of model (can be CIM and other model file formats)
|
||||||
Files []File `gorm:"foreignkey:ModelID"`
|
Files []File `gorm:"foreignkey:ModelID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Signal struct {
|
type Signal struct {
|
||||||
// Name of Signal
|
// Name of Signal
|
||||||
Name string
|
Name string
|
||||||
// Unit of Signal
|
// Unit of Signal
|
||||||
Unit string
|
Unit string
|
||||||
// Index of the Signal in the mapping
|
// Index of the Signal in the mapping
|
||||||
Index uint
|
Index uint
|
||||||
// Direction of the signal (in or out)
|
// Direction of the signal (in or out)
|
||||||
Direction string
|
Direction string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Simulator data model
|
// Simulator data model
|
||||||
type Simulator struct {
|
type Simulator struct {
|
||||||
// ID of the simulator
|
// ID of the simulator
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// UUID of the simulator
|
// UUID of the simulator
|
||||||
UUID string `gorm:"unique;not null"`
|
UUID string `gorm:"unique;not null"`
|
||||||
// Host if the simulator
|
// Host if the simulator
|
||||||
Host string `gorm:"default:''"`
|
Host string `gorm:"default:''"`
|
||||||
// Model type supported by the simulator
|
// Model type supported by the simulator
|
||||||
Modeltype string `gorm:"default:''"`
|
Modeltype string `gorm:"default:''"`
|
||||||
// Uptime of the simulator
|
// Uptime of the simulator
|
||||||
Uptime int `gorm:"default:0"`
|
Uptime int `gorm:"default:0"`
|
||||||
// State of the simulator
|
// State of the simulator
|
||||||
State string `gorm:"default:''"`
|
State string `gorm:"default:''"`
|
||||||
// Time of last state update
|
// Time of last state update
|
||||||
StateUpdateAt time.Time
|
StateUpdateAt time.Time
|
||||||
// Properties of simulator as JSON string
|
// Properties of simulator as JSON string
|
||||||
Properties string
|
Properties string
|
||||||
// Raw properties of simulator as JSON string
|
// Raw properties of simulator as JSON string
|
||||||
RawProperties string
|
RawProperties string
|
||||||
}
|
}
|
||||||
|
@ -102,69 +100,67 @@ type Simulator struct {
|
||||||
// Visualization data model
|
// Visualization data model
|
||||||
type Visualization struct {
|
type Visualization struct {
|
||||||
// ID of visualization
|
// ID of visualization
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// Name of visualization
|
// Name of visualization
|
||||||
Name string `gorm:"not null"`
|
Name string `gorm:"not null"`
|
||||||
// Grid of visualization
|
// Grid of visualization
|
||||||
Grid int `gorm:"default:15"`
|
Grid int `gorm:"default:15"`
|
||||||
// ID of simulation to which visualization belongs
|
// ID of simulation to which visualization belongs
|
||||||
SimulationID uint `gorm:"not null"`
|
SimulationID uint `gorm:"not null"`
|
||||||
// Widgets that belong to visualization
|
// Widgets that belong to visualization
|
||||||
Widgets []Widget `gorm:"foreignkey:VisualizationID"`
|
Widgets []Widget `gorm:"foreignkey:VisualizationID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Widget data model
|
// Widget data model
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
// ID of widget
|
// ID of widget
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// Name of widget
|
// Name of widget
|
||||||
Name string `gorm:"not null"`
|
Name string `gorm:"not null"`
|
||||||
// Type of widget
|
// Type of widget
|
||||||
Type string `gorm:"not null"`
|
Type string `gorm:"not null"`
|
||||||
// Width of widget
|
// Width of widget
|
||||||
Width uint `gorm:"not null"`
|
Width uint `gorm:"not null"`
|
||||||
// Height of widget
|
// Height of widget
|
||||||
Height uint `gorm:"not null"`
|
Height uint `gorm:"not null"`
|
||||||
// Minimal width of widget
|
// Minimal width of widget
|
||||||
MinWidth uint `gorm:"not null"`
|
MinWidth uint `gorm:"not null"`
|
||||||
// Minimal height of widget
|
// Minimal height of widget
|
||||||
MinHeight uint `gorm:"not null"`
|
MinHeight uint `gorm:"not null"`
|
||||||
// X position of widget
|
// X position of widget
|
||||||
X int `gorm:"not null"`
|
X int `gorm:"not null"`
|
||||||
// Y position of widget
|
// Y position of widget
|
||||||
Y int `gorm:"not null"`
|
Y int `gorm:"not null"`
|
||||||
// Z position of widget
|
// Z position of widget
|
||||||
Z int `gorm:"not null"`
|
Z int `gorm:"not null"`
|
||||||
// Locked state of widget
|
// Locked state of widget
|
||||||
IsLocked bool `gorm:"default:false"`
|
IsLocked bool `gorm:"default:false"`
|
||||||
// Custom properties of widget as JSON string
|
// Custom properties of widget as JSON string
|
||||||
CustomProperties string
|
CustomProperties string
|
||||||
// ID of visualization to which widget belongs
|
// ID of visualization to which widget belongs
|
||||||
VisualizationID uint `gorm:"not null"`
|
VisualizationID uint `gorm:"not null"`
|
||||||
// Files that belong to widget (for example images)
|
// Files that belong to widget (for example images)
|
||||||
Files []File `gorm:"foreignkey:WidgetID"`
|
Files []File `gorm:"foreignkey:WidgetID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// File data model
|
// File data model
|
||||||
type File struct {
|
type File struct {
|
||||||
// ID of file
|
// ID of file
|
||||||
ID uint `gorm:"primary_key;auto_increment"`
|
ID uint `gorm:"primary_key;auto_increment"`
|
||||||
// Name of file
|
// Name of file
|
||||||
Name string `gorm:"not null"`
|
Name string `gorm:"not null"`
|
||||||
// Path at which file is saved at server side
|
// Path at which file is saved at server side
|
||||||
Path string `gorm:"not null"`
|
Path string `gorm:"not null"`
|
||||||
// Type of file (MIME type)
|
// Type of file (MIME type)
|
||||||
Type string `gorm:"not null"`
|
Type string `gorm:"not null"`
|
||||||
// Size of file (in byte)
|
// Size of file (in byte)
|
||||||
Size uint `gorm:"not null"`
|
Size uint `gorm:"not null"`
|
||||||
// Height of image (only needed in case of image)
|
// Height of image (only needed in case of image)
|
||||||
ImageHeight uint
|
ImageHeight uint
|
||||||
// Width of image (only needed in case of image)
|
// Width of image (only needed in case of image)
|
||||||
ImageWidth uint
|
ImageWidth uint
|
||||||
// Last modification time of file
|
// Last modification time of file
|
||||||
Date time.Time
|
Date time.Time
|
||||||
// ID of model to which file belongs
|
// ID of model to which file belongs
|
||||||
ModelID uint `gorm:""`
|
ModelID uint `gorm:""`
|
||||||
// ID of widget to which file belongs
|
// ID of widget to which file belongs
|
||||||
|
|
Loading…
Add table
Reference in a new issue