VILLASweb-backend-go/serializers/simulationSerializer.go
2019-05-21 16:51:34 +02:00

44 lines
1 KiB
Go

package serializers
import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
type SimulationsSerializer struct {
Ctx *gin.Context
Simulations []common.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
common.Simulation
}
type SimulationResponse struct {
Name string `json:"Name"`
ID uint `json:"SimulationID"`
Running bool `json:"Running"`
StartParams postgres.Jsonb `json:"Starting Parameters"`
}
func (self *SimulationSerializer) Response() SimulationResponse {
response := SimulationResponse{
Name: self.Name,
ID: self.ID,
Running: self.Running,
StartParams: self.StartParameters,
}
return response
}