VILLASweb-backend-go/routes/simulator/simulatorSerializer.go
Sonja Happ 2e7475a26b - add first draft of code for other routes (not complete!)
- some new endpoints
- some new DB queries
- some new serializers
2019-05-09 17:02:24 +02:00

52 lines
1.1 KiB
Go

package simulator
import (
"time"
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
type SimulatorsSerializer struct {
Ctx *gin.Context
Simulators []common.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
common.Simulator
}
type SimulatorResponse struct {
UUID string `json:"UUID"`
Host string `json:"Host"`
ModelType string `json:"ModelType"`
Uptime int `json:"Uptime"`
State string `json:"State"`
StateUpdateAt time.Time `json:"StateUpdateAt"`
// Properties
// Raw Properties
}
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
}