mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
245 lines
5 KiB
Go
245 lines
5 KiB
Go
package common
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// User/s Serializers
|
|
|
|
type UsersSerializer struct {
|
|
Ctx *gin.Context
|
|
Users []User
|
|
}
|
|
|
|
func (self *UsersSerializer) Response() []UserResponse {
|
|
response := []UserResponse{}
|
|
for _, user := range self.Users {
|
|
serializer := UserSerializer{self.Ctx, user}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type UserSerializer struct {
|
|
Ctx *gin.Context
|
|
User
|
|
}
|
|
|
|
func (self *UserSerializer) Response() UserResponse {
|
|
response := UserResponse{
|
|
Username: self.Username,
|
|
Role: self.Role,
|
|
Mail: self.Mail,
|
|
}
|
|
return response
|
|
}
|
|
|
|
// Simulation/s Serializers
|
|
|
|
type SimulationsSerializer struct {
|
|
Ctx *gin.Context
|
|
Simulations []Simulation
|
|
}
|
|
|
|
func (self *SimulationsSerializer) Response() []SimulationResponse {
|
|
response := []SimulationResponse{}
|
|
for _, simulation := range self.Simulations {
|
|
serializer := SimulationSerializer{self.Ctx, simulation}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type SimulationSerializer struct {
|
|
Ctx *gin.Context
|
|
Simulation
|
|
}
|
|
|
|
|
|
func (self *SimulationSerializer) Response() SimulationResponse {
|
|
response := SimulationResponse{
|
|
Name: self.Name,
|
|
ID: self.ID,
|
|
Running: self.Running,
|
|
StartParams: self.StartParameters,
|
|
}
|
|
return response
|
|
}
|
|
|
|
|
|
// Model/s Serializers
|
|
|
|
type ModelsSerializer struct {
|
|
Ctx *gin.Context
|
|
Models []Model
|
|
}
|
|
|
|
func (self *ModelsSerializer) Response() []ModelResponse {
|
|
response := []ModelResponse{}
|
|
for _, model := range self.Models {
|
|
serializer := ModelSerializer{self.Ctx, model}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type ModelSerializer struct {
|
|
Ctx *gin.Context
|
|
Model
|
|
}
|
|
|
|
func (self *ModelSerializer) Response() ModelResponse {
|
|
response := ModelResponse{
|
|
Name: self.Name,
|
|
OutputLength: self.OutputLength,
|
|
InputLength: self.InputLength,
|
|
SimulationID: self.SimulationID,
|
|
SimulatorID: self.SimulatorID,
|
|
StartParams: self.StartParameters,
|
|
//InputMapping
|
|
//OutputMapping
|
|
}
|
|
return response
|
|
}
|
|
|
|
// Simulator/s Serializers
|
|
|
|
type SimulatorsSerializer struct {
|
|
Ctx *gin.Context
|
|
Simulators []Simulator
|
|
}
|
|
|
|
func (self *SimulatorsSerializer) Response() []SimulatorResponse {
|
|
response := []SimulatorResponse{}
|
|
for _, simulator := range self.Simulators {
|
|
serializer := SimulatorSerializer{self.Ctx, simulator}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type SimulatorSerializer struct {
|
|
Ctx *gin.Context
|
|
Simulator
|
|
}
|
|
|
|
func (self *SimulatorSerializer) Response() SimulatorResponse {
|
|
|
|
response := SimulatorResponse{
|
|
UUID: self.UUID,
|
|
Host: self.Host,
|
|
ModelType: self.Modeltype,
|
|
Uptime: self.Uptime,
|
|
State: self.State,
|
|
StateUpdateAt: self.StateUpdateAt,
|
|
}
|
|
return response
|
|
}
|
|
|
|
// Visualization/s Serializers
|
|
|
|
type VisualizationsSerializer struct {
|
|
Ctx *gin.Context
|
|
Visualizations []Visualization
|
|
}
|
|
|
|
func (self *VisualizationsSerializer) Response() []VisualizationResponse {
|
|
response := []VisualizationResponse{}
|
|
for _, visualization := range self.Visualizations {
|
|
serializer := VisualizationSerializer{self.Ctx, visualization}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type VisualizationSerializer struct {
|
|
Ctx *gin.Context
|
|
Visualization
|
|
}
|
|
|
|
|
|
func (self *VisualizationSerializer) Response() VisualizationResponse {
|
|
|
|
response := VisualizationResponse{
|
|
Name: self.Name,
|
|
Grid: self.Grid,
|
|
SimulationID: self.SimulationID,
|
|
}
|
|
return response
|
|
}
|
|
|
|
// Widget/s Serializers
|
|
|
|
type WidgetsSerializer struct {
|
|
Ctx *gin.Context
|
|
Widgets []Widget
|
|
}
|
|
|
|
func (self *WidgetsSerializer) Response() []WidgetResponse {
|
|
response := []WidgetResponse{}
|
|
for _, widget := range self.Widgets {
|
|
serializer := WidgetSerializer{self.Ctx, widget}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type WidgetSerializer struct {
|
|
Ctx *gin.Context
|
|
Widget
|
|
}
|
|
|
|
func (self *WidgetSerializer) Response() WidgetResponse {
|
|
|
|
response := WidgetResponse{
|
|
Name: self.Name,
|
|
Type: self.Type,
|
|
Width: self.Width,
|
|
Height: self.Height,
|
|
MinWidth: self.MinWidth,
|
|
MinHeight: self.MinHeight,
|
|
X: self.X,
|
|
Y: self.Y,
|
|
Z: self.Z,
|
|
VisualizationID: self.VisualizationID,
|
|
IsLocked: self.IsLocked,
|
|
//CustomProperties
|
|
}
|
|
return response
|
|
}
|
|
|
|
// File/s Serializers
|
|
|
|
type FilesSerializerNoAssoc struct {
|
|
Ctx *gin.Context
|
|
Files []File
|
|
}
|
|
|
|
func (self *FilesSerializerNoAssoc) Response() []FileResponse {
|
|
response := []FileResponse{}
|
|
for _, files := range self.Files {
|
|
serializer := FileSerializerNoAssoc{self.Ctx, files}
|
|
response = append(response, serializer.Response())
|
|
}
|
|
return response
|
|
}
|
|
|
|
type FileSerializerNoAssoc struct {
|
|
Ctx *gin.Context
|
|
File
|
|
}
|
|
|
|
|
|
func (self *FileSerializerNoAssoc) Response() FileResponse {
|
|
response := FileResponse{
|
|
Name: self.Name,
|
|
ID: self.ID,
|
|
Path: self.Path,
|
|
Type: self.Type,
|
|
Size: self.Size,
|
|
H: self.ImageHeight,
|
|
W: self.ImageWidth,
|
|
// Date
|
|
}
|
|
return response
|
|
}
|