mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
- add first draft of code for other routes (not complete!)
- some new endpoints - some new DB queries - some new serializers
This commit is contained in:
parent
eea765f707
commit
2e7475a26b
28 changed files with 698 additions and 173 deletions
|
@ -8,16 +8,16 @@ import (
|
|||
func FilesRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", filesReadEp)
|
||||
//r.POST("/", fileRegistrationEp) // TODO to be added to API
|
||||
//r.PUT("/:fileID", fileUpdateEp) // TODO to be added to API
|
||||
r.GET("/:fileID", fileReadEp)
|
||||
r.DELETE("/:fileID", fileDeleteEp)
|
||||
//r.PUT("/:FileID", fileUpdateEp) // TODO to be added to API
|
||||
r.GET("/:FileID", fileReadEp)
|
||||
r.DELETE("/:FileID", fileDeleteEp)
|
||||
}
|
||||
|
||||
func filesReadEp(c *gin.Context) {
|
||||
allFiles, _, _ := FindAllFiles()
|
||||
serializer := FilesSerializer{c, allFiles}
|
||||
serializer := FilesSerializerNoAssoc{c, allFiles}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"users": serializer.Response(),
|
||||
"files": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -10,3 +10,10 @@ func FindAllFiles() ([]common.File, int, error) {
|
|||
err := db.Find(&files).Error
|
||||
return files, len(files), err
|
||||
}
|
||||
|
||||
func FindUserFiles(user *common.User) ([]common.File, int, error) {
|
||||
db := common.GetDB()
|
||||
var files []common.File
|
||||
err := db.Model(user).Related(&files, "Files").Error
|
||||
return files, len(files), err
|
||||
}
|
|
@ -1,53 +1,53 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
type FilesSerializer struct {
|
||||
// File/s Serializers
|
||||
|
||||
type FilesSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
Files []common.File
|
||||
}
|
||||
|
||||
func (self *FilesSerializer) Response() []FileResponse {
|
||||
response := []FileResponse{}
|
||||
for _, File := range self.Files {
|
||||
serializer := FileSerializer{self.Ctx, File}
|
||||
func (self *FilesSerializerNoAssoc) Response() []FileResponseNoAssoc {
|
||||
response := []FileResponseNoAssoc{}
|
||||
for _, files := range self.Files {
|
||||
serializer := FileSerializerNoAssoc{self.Ctx, files}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type FileSerializer struct {
|
||||
type FileSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.File
|
||||
}
|
||||
|
||||
type FileResponse struct {
|
||||
type FileResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
ID uint `json:"FileID"`
|
||||
Path string `json:"Path"`
|
||||
Type string `json:"Type"` //MIME type?
|
||||
Type string `json:"Type"`
|
||||
Size uint `json:"Size"`
|
||||
H uint `json:"ImageHeight"`
|
||||
W uint `json:"ImageWidth"`
|
||||
Date time.Time `json:"Date"`
|
||||
// Date
|
||||
}
|
||||
|
||||
func (self *FileSerializer) Response() FileResponse {
|
||||
|
||||
response := FileResponse{
|
||||
Name: self.Name,
|
||||
Path: self.Path,
|
||||
Type: self.Type,
|
||||
Size: self.Size,
|
||||
Date: self.Date,
|
||||
H: self.ImageHeight,
|
||||
func (self *FileSerializerNoAssoc) Response() FileResponseNoAssoc {
|
||||
response := FileResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
ID: self.ID,
|
||||
Path: self.Path,
|
||||
Type: self.Type,
|
||||
Size: self.Size,
|
||||
H: self.ImageHeight,
|
||||
W: self.ImageWidth,
|
||||
// Date
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
|
@ -1 +1,46 @@
|
|||
package project
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ProjectsRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", projectsReadEp)
|
||||
r.POST("/", projectRegistrationEp)
|
||||
r.PUT("/:ProjectID", projectUpdateEp)
|
||||
r.GET("/:ProjectID", projectReadEp)
|
||||
r.DELETE("/:ProjectID", projectDeleteEp)
|
||||
}
|
||||
|
||||
func projectsReadEp(c *gin.Context) {
|
||||
allProjects, _, _ := FindAllProjects()
|
||||
serializer := ProjectsSerializerNoAssoc{c, allProjects}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"projects": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
func projectRegistrationEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func projectUpdateEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func projectReadEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func projectDeleteEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1 +1,28 @@
|
|||
package project
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
func FindAllProjects() ([]common.Project, int, error) {
|
||||
db := common.GetDB()
|
||||
var projects []common.Project
|
||||
err := db.Find(&projects).Error
|
||||
return projects, len(projects), err
|
||||
}
|
||||
|
||||
func FindUserProjects(user *common.User) ([]common.Project, int, error) {
|
||||
db := common.GetDB()
|
||||
var projects []common.Project
|
||||
err := db.Model(user).Related(&projects, "Projects").Error
|
||||
return projects, len(projects), err
|
||||
}
|
||||
|
||||
func FindVisualizationProject(visualization *common.Visualization) (common.Project, int, error) {
|
||||
db := common.GetDB()
|
||||
var project common.Project
|
||||
err := db.Model(visualization).Related(&project, "Projects").Error
|
||||
return project, 1, err
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,41 @@
|
|||
package project
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
type ProjectsSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
Projects []common.Project
|
||||
}
|
||||
|
||||
func (self *ProjectsSerializerNoAssoc) Response() []ProjectResponseNoAssoc {
|
||||
response := []ProjectResponseNoAssoc{}
|
||||
for _, project := range self.Projects {
|
||||
serializer := ProjectSerializerNoAssoc{self.Ctx, project}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type ProjectSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.Project
|
||||
}
|
||||
|
||||
type ProjectResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
ID uint `json:"ProjectID"`
|
||||
}
|
||||
|
||||
func (self *ProjectSerializerNoAssoc) Response() ProjectResponseNoAssoc {
|
||||
response := ProjectResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
ID: self.ID,
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
package signal
|
||||
|
||||
|
||||
//TODO extend API with signal endpoints
|
|
@ -1 +1,3 @@
|
|||
package signal
|
||||
|
||||
//TODO extend API with signal endpoints
|
|
@ -1 +1,3 @@
|
|||
package signal
|
||||
|
||||
//TODO extend API with signal endpoints
|
|
@ -1 +1,47 @@
|
|||
package simulation
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SimulationsRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", simulationsReadEp)
|
||||
r.POST("/", simulationRegistrationEp)
|
||||
r.PUT("/:SimulationID", simulationUpdateEp)
|
||||
r.GET("/:SimulationID", simulationReadEp)
|
||||
r.DELETE("/:SimulationID", simulationDeleteEp)
|
||||
}
|
||||
|
||||
func simulationsReadEp(c *gin.Context) {
|
||||
allSimulations, _, _ := FindAllSimulations()
|
||||
serializer := SimulationsSerializerNoAssoc{c, allSimulations}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"simulations": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
func simulationRegistrationEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulationUpdateEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulationReadEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulationDeleteEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,19 @@
|
|||
package simulation
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
func FindAllSimulations() ([]common.Simulation, int, error) {
|
||||
db := common.GetDB()
|
||||
var simulations []common.Simulation
|
||||
err := db.Find(&simulations).Error
|
||||
return simulations, len(simulations), err
|
||||
}
|
||||
|
||||
func FindUserSimulations(user *common.User) ([]common.Simulation, int, error) {
|
||||
db := common.GetDB()
|
||||
var simulations []common.Simulation
|
||||
err := db.Model(user).Related(&simulations, "Simulations").Error
|
||||
return simulations, len(simulations), err
|
||||
}
|
||||
|
|
|
@ -1 +1,43 @@
|
|||
package simulation
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
type SimulationsSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
Simulations []common.Simulation
|
||||
}
|
||||
|
||||
func (self *SimulationsSerializerNoAssoc) Response() []SimulationResponseNoAssoc {
|
||||
response := []SimulationResponseNoAssoc{}
|
||||
for _, simulation := range self.Simulations {
|
||||
serializer := SimulationSerializerNoAssoc{self.Ctx, simulation}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type SimulationSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.Simulation
|
||||
}
|
||||
|
||||
type SimulationResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
ID uint `json:"SimulationID"`
|
||||
Running bool `json:"Running"`
|
||||
//StartParams postgres.Jsonb `json:"Starting Parameters"`
|
||||
}
|
||||
|
||||
func (self *SimulationSerializerNoAssoc) Response() SimulationResponseNoAssoc {
|
||||
response := SimulationResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
ID: self.ID,
|
||||
Running: self.Running,
|
||||
//StartParams: self.StartParameters,
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
|
@ -1 +1,46 @@
|
|||
package simulationmodel
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SimulationModelsRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", simulationmodelsReadEp)
|
||||
r.POST("/", simulationmodelRegistrationEp)
|
||||
r.PUT("/:SimulationModelID", simulationmodelUpdateEp)
|
||||
r.GET("/:SimulationModelID", simulationmodelReadEp)
|
||||
r.DELETE("/:SimulationModelID", simulationmodelDeleteEp)
|
||||
}
|
||||
|
||||
func simulationmodelsReadEp(c *gin.Context) {
|
||||
allSimulationModels, _, _ := FindAllSimulationModels()
|
||||
serializer := SimulationModelsSerializerNoAssoc{c, allSimulationModels}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"simulationmodels": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
func simulationmodelRegistrationEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulationmodelUpdateEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulationmodelReadEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulationmodelDeleteEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1 +1,12 @@
|
|||
package simulationmodel
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
func FindAllSimulationModels() ([]common.SimulationModel, int, error) {
|
||||
db := common.GetDB()
|
||||
var simulationmodels []common.SimulationModel
|
||||
err := db.Find(&simulationmodels).Error
|
||||
return simulationmodels, len(simulationmodels), err
|
||||
}
|
||||
|
|
|
@ -1 +1,52 @@
|
|||
package simulationmodel
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
type SimulationModelsSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
SimulationModels []common.SimulationModel
|
||||
}
|
||||
|
||||
func (self *SimulationModelsSerializerNoAssoc) Response() []SimulationModelResponseNoAssoc {
|
||||
response := []SimulationModelResponseNoAssoc{}
|
||||
for _, simulationmodel := range self.SimulationModels {
|
||||
serializer := SimulationModelSerializerNoAssoc{self.Ctx, simulationmodel}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type SimulationModelSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.SimulationModel
|
||||
}
|
||||
|
||||
type SimulationModelResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
OutputLength int `json:"OutputLength"`
|
||||
InputLength int `json:"InputLength"`
|
||||
BelongsToSimulationID uint `json:"BelongsToSimulationID"`
|
||||
BelongsToSimulatorID uint `json:"BelongsToSimulatiorID"`
|
||||
//StartParams postgres.Jsonb `json:"Starting Parameters"`
|
||||
//Output Mapping
|
||||
//Input Mapping
|
||||
}
|
||||
|
||||
func (self *SimulationModelSerializerNoAssoc) Response() SimulationModelResponseNoAssoc {
|
||||
response := SimulationModelResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
OutputLength: self.OutputLength,
|
||||
InputLength: self.InputLength,
|
||||
BelongsToSimulationID: self.BelongsToSimulationID,
|
||||
BelongsToSimulatorID: self.BelongsToSimulatorID,
|
||||
//StartParams: self.StartParameters,
|
||||
//InputMapping
|
||||
//OutputMapping
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,53 @@
|
|||
package simulator
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SimulatorsRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", simulatorsReadEp)
|
||||
r.POST("/", simulatorRegistrationEp)
|
||||
r.PUT("/:SimulatorID", simulatorUpdateEp)
|
||||
r.GET("/:SimulatorID", simulatorReadEp)
|
||||
r.DELETE("/:SimulatorID", simulatorDeleteEp)
|
||||
r.POST("/:SimulatorID", simulatorSendActionEp)
|
||||
}
|
||||
|
||||
func simulatorsReadEp(c *gin.Context) {
|
||||
allSimulators, _, _ := FindAllSimulators()
|
||||
serializer := SimulatorsSerializer{c, allSimulators}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"simulators": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
func simulatorRegistrationEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulatorUpdateEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulatorReadEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulatorDeleteEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func simulatorSendActionEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
|
@ -1 +1,13 @@
|
|||
package simulator
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
func FindAllSimulators() ([]common.Simulator, int, error) {
|
||||
db := common.GetDB()
|
||||
var simulators []common.Simulator
|
||||
err := db.Find(&simulators).Error
|
||||
return simulators, len(simulators), err
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,52 @@
|
|||
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
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
func UsersRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", usersReadEp)
|
||||
r.POST("/", userRegistrationEp)
|
||||
r.PUT("/:userID", userUpdateEp)
|
||||
r.GET("/:userID", userReadEp)
|
||||
r.DELETE("/:userID", userDeleteEp)
|
||||
r.PUT("/:UserID", userUpdateEp)
|
||||
r.GET("/:UserID", userReadEp)
|
||||
r.DELETE("/:UserID", userDeleteEp)
|
||||
//r.GET("/me", userSelfEp) // TODO: this conflicts with GET /:userID
|
||||
}
|
||||
|
||||
|
|
|
@ -10,24 +10,3 @@ func FindAllUsers() ([]common.User, int, error) {
|
|||
err := db.Find(&users).Error
|
||||
return users, len(users), err
|
||||
}
|
||||
|
||||
func FindUserProjects(user *common.User) ([]common.Project, int, error) {
|
||||
db := common.GetDB()
|
||||
var projects []common.Project
|
||||
err := db.Model(user).Related(&projects, "Projects").Error
|
||||
return projects, len(projects), err
|
||||
}
|
||||
|
||||
func FindUserSimulations(user *common.User) ([]common.Simulation, int, error) {
|
||||
db := common.GetDB()
|
||||
var simulations []common.Simulation
|
||||
err := db.Model(user).Related(&simulations, "Simulations").Error
|
||||
return simulations, len(simulations), err
|
||||
}
|
||||
|
||||
func FindUserFiles(user *common.User) ([]common.File, int, error) {
|
||||
db := common.GetDB()
|
||||
var files []common.File
|
||||
err := db.Model(user).Related(&files, "Files").Error
|
||||
return files, len(files), err
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/project"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
|
||||
)
|
||||
|
||||
type UsersSerializer struct {
|
||||
|
@ -30,21 +33,21 @@ type UserResponse struct {
|
|||
Password string `json:"Password"` // XXX: ???
|
||||
Role string `json:"Role"`
|
||||
Mail string `json:"Mail"`
|
||||
Projects []ProjectResponseNoAssoc
|
||||
Simulations []SimulationResponseNoAssoc
|
||||
Files []FileResponseNoAssoc
|
||||
Projects []project.ProjectResponseNoAssoc
|
||||
Simulations []simulation.SimulationResponseNoAssoc
|
||||
Files []file.FileResponseNoAssoc
|
||||
}
|
||||
|
||||
func (self *UserSerializer) Response() UserResponse {
|
||||
// TODO: maybe all those should be made in one transaction
|
||||
projects, _, _ := FindUserProjects(&self.User)
|
||||
projectsSerializer := ProjectsSerializerNoAssoc{self.Ctx, projects}
|
||||
projects, _, _ := project.FindUserProjects(&self.User)
|
||||
projectsSerializer := project.ProjectsSerializerNoAssoc{self.Ctx, projects}
|
||||
|
||||
simulations, _, _ := FindUserSimulations(&self.User)
|
||||
simulationsSerializer := SimulationsSerializerNoAssoc{self.Ctx, simulations}
|
||||
simulations, _, _ := simulation.FindUserSimulations(&self.User)
|
||||
simulationsSerializer := simulation.SimulationsSerializerNoAssoc{self.Ctx, simulations}
|
||||
|
||||
files, _, _ := FindUserFiles(&self.User)
|
||||
filesSerializer := FilesSerializerNoAssoc{self.Ctx, files}
|
||||
files, _, _ := file.FindUserFiles(&self.User)
|
||||
filesSerializer := file.FilesSerializerNoAssoc{self.Ctx, files}
|
||||
|
||||
response := UserResponse{
|
||||
Username: self.Username,
|
||||
|
@ -58,120 +61,6 @@ func (self *UserSerializer) Response() UserResponse {
|
|||
return response
|
||||
}
|
||||
|
||||
// Project/s Serializers
|
||||
|
||||
type ProjectsSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
Projects []common.Project
|
||||
}
|
||||
|
||||
func (self *ProjectsSerializerNoAssoc) Response() []ProjectResponseNoAssoc {
|
||||
response := []ProjectResponseNoAssoc{}
|
||||
for _, project := range self.Projects {
|
||||
serializer := ProjectSerializerNoAssoc{self.Ctx, project}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type ProjectSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.Project
|
||||
}
|
||||
|
||||
type ProjectResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
ID uint `json:"ProjectID"`
|
||||
}
|
||||
|
||||
func (self *ProjectSerializerNoAssoc) Response() ProjectResponseNoAssoc {
|
||||
response := ProjectResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
ID: self.ID,
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// Simulation/s Serializers
|
||||
|
||||
type SimulationsSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
Simulations []common.Simulation
|
||||
}
|
||||
|
||||
func (self *SimulationsSerializerNoAssoc) Response() []SimulationResponseNoAssoc {
|
||||
response := []SimulationResponseNoAssoc{}
|
||||
for _, simulation := range self.Simulations {
|
||||
serializer := SimulationSerializerNoAssoc{self.Ctx, simulation}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type SimulationSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.Simulation
|
||||
}
|
||||
|
||||
type SimulationResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
ID uint `json:"SimulationID"`
|
||||
Running bool `json:"Running"`
|
||||
//StartParams postgres.Jsonb `json:"Starting Parameters"`
|
||||
}
|
||||
|
||||
func (self *SimulationSerializerNoAssoc) Response() SimulationResponseNoAssoc {
|
||||
response := SimulationResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
ID: self.ID,
|
||||
Running: self.Running,
|
||||
//StartParams: self.StartParameters,
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// File/s Serializers
|
||||
|
||||
type FilesSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
Files []common.File
|
||||
}
|
||||
|
||||
func (self *FilesSerializerNoAssoc) Response() []FileResponseNoAssoc {
|
||||
response := []FileResponseNoAssoc{}
|
||||
for _, files := range self.Files {
|
||||
serializer := FileSerializerNoAssoc{self.Ctx, files}
|
||||
response = append(response, serializer.Response())
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
type FileSerializerNoAssoc struct {
|
||||
Ctx *gin.Context
|
||||
common.File
|
||||
}
|
||||
|
||||
type FileResponseNoAssoc struct {
|
||||
Name string `json:"Name"`
|
||||
ID uint `json:"FileID"`
|
||||
Path string `json:"Path"`
|
||||
Type string `json:"Type"`
|
||||
Size uint `json:"Size"`
|
||||
H uint `json:"ImageHeight"`
|
||||
W uint `json:"ImageWidth"`
|
||||
// Date
|
||||
}
|
||||
|
||||
func (self *FileSerializerNoAssoc) Response() FileResponseNoAssoc {
|
||||
response := FileResponseNoAssoc{
|
||||
Name: self.Name,
|
||||
ID: self.ID,
|
||||
Path: self.Path,
|
||||
Type: self.Type,
|
||||
Size: self.Size,
|
||||
H: self.ImageHeight,
|
||||
W: self.ImageWidth,
|
||||
// Date
|
||||
}
|
||||
return response
|
||||
}
|
|
@ -1 +1,46 @@
|
|||
package visualization
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func VisualizationsRegister(r *gin.RouterGroup) {
|
||||
r.GET("/", visualizationsReadEp)
|
||||
r.POST("/", visualizationRegistrationEp)
|
||||
r.PUT("/:VisualizationID", visualizationUpdateEp)
|
||||
r.GET("/:VisualizationID", visualizationReadEp)
|
||||
r.DELETE("/:VisualizationID", visualizationDeleteEp)
|
||||
}
|
||||
|
||||
func visualizationsReadEp(c *gin.Context) {
|
||||
allVisualizations, _, _ := FindAllVisualizations()
|
||||
serializer := VisualizationsSerializer{c, allVisualizations}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"visualizations": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
func visualizationRegistrationEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func visualizationUpdateEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func visualizationReadEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func visualizationDeleteEp(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1 +1,12 @@
|
|||
package visualization
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
func FindAllVisualizations() ([]common.Visualization, int, error) {
|
||||
db := common.GetDB()
|
||||
var visualization []common.Visualization
|
||||
err := db.Find(&visualization).Error
|
||||
return visualization, len(visualization), err
|
||||
}
|
||||
|
|
|
@ -1 +1,59 @@
|
|||
package visualization
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/project"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/widget"
|
||||
)
|
||||
|
||||
type VisualizationsSerializer struct {
|
||||
Ctx *gin.Context
|
||||
Visualizations []common.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
|
||||
common.Visualization
|
||||
}
|
||||
|
||||
type VisualizationResponse struct {
|
||||
Name string `json:"Name"`
|
||||
UserID uint `json:"UserID"`
|
||||
Grid int `json:"Grid"`
|
||||
ProjectID uint `json:"ProjectID"`
|
||||
Project project.ProjectResponseNoAssoc
|
||||
Widgets []widget.WidgetResponse
|
||||
}
|
||||
|
||||
func (self *VisualizationSerializer) Response() VisualizationResponse {
|
||||
|
||||
// TODO: maybe all those should be made in one transaction
|
||||
p, _, _ := project.FindVisualizationProject(&self.Visualization)
|
||||
projectSerializer := project.ProjectSerializerNoAssoc{self.Ctx, p}
|
||||
|
||||
w, _, _:= widget.FindVisualizationWidgets(&self.Visualization)
|
||||
widgetsSerializer := widget.WidgetsSerializer{self.Ctx, w}
|
||||
|
||||
|
||||
response := VisualizationResponse{
|
||||
Name: self.Name,
|
||||
UserID: self.UserID,
|
||||
Grid: self.Grid,
|
||||
ProjectID: self.ProjectID,
|
||||
Project: projectSerializer.Response(),
|
||||
Widgets: widgetsSerializer.Response(),
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
package widget
|
||||
|
||||
// TODO add new API endpoints for widgets
|
||||
|
|
|
@ -1 +1,14 @@
|
|||
package widget
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
func FindVisualizationWidgets(visualization *common.Visualization) ([]common.Widget, int, error) {
|
||||
db := common.GetDB()
|
||||
var widgets []common.Widget
|
||||
err := db.Model(visualization).Related(&widgets, "Widgets").Error
|
||||
return widgets, len(widgets), err
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,60 @@
|
|||
package widget
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
)
|
||||
|
||||
type WidgetsSerializer struct {
|
||||
Ctx *gin.Context
|
||||
Widgets []common.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
|
||||
common.Widget
|
||||
}
|
||||
|
||||
type WidgetResponse struct {
|
||||
Name string `json:"Name"`
|
||||
Type string `json:"Type"`
|
||||
Width uint `json:"Width"`
|
||||
Height uint `json:"Height"`
|
||||
MinWidth uint `json:"MinWidth"`
|
||||
MinHeight uint `json:"MinHeight"`
|
||||
X int `json:"X"`
|
||||
Y int `json:"Y"`
|
||||
Z int `json:"Z"`
|
||||
VisualizationID uint `json:"VisualizationID"`
|
||||
IsLocked bool `json:"IsLocked"`
|
||||
//CustomProperties
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
15
start.go
15
start.go
|
@ -2,7 +2,13 @@ package main
|
|||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/project"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulationmodel"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/visualization"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
@ -17,6 +23,15 @@ func main() {
|
|||
|
||||
api := r.Group("/api")
|
||||
user.UsersRegister(api.Group("/users"))
|
||||
file.FilesRegister(api.Group("/files"))
|
||||
project.ProjectsRegister(api.Group("/projects"))
|
||||
simulation.SimulationsRegister(api.Group("/simulations"))
|
||||
simulationmodel.SimulationModelsRegister(api.Group("/models"))
|
||||
simulator.SimulatorsRegister(api.Group("/simulators"))
|
||||
visualization.VisualizationsRegister(api.Group("/visualizations"))
|
||||
|
||||
|
||||
|
||||
|
||||
r.Run()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue