- 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:
Sonja Happ 2019-05-09 17:02:24 +02:00
parent eea765f707
commit 2e7475a26b
28 changed files with 698 additions and 173 deletions

View file

@ -8,16 +8,16 @@ import (
func FilesRegister(r *gin.RouterGroup) { func FilesRegister(r *gin.RouterGroup) {
r.GET("/", filesReadEp) r.GET("/", filesReadEp)
//r.POST("/", fileRegistrationEp) // TODO to be added to API //r.POST("/", fileRegistrationEp) // TODO to be added to API
//r.PUT("/:fileID", fileUpdateEp) // TODO to be added to API //r.PUT("/:FileID", fileUpdateEp) // TODO to be added to API
r.GET("/:fileID", fileReadEp) r.GET("/:FileID", fileReadEp)
r.DELETE("/:fileID", fileDeleteEp) r.DELETE("/:FileID", fileDeleteEp)
} }
func filesReadEp(c *gin.Context) { func filesReadEp(c *gin.Context) {
allFiles, _, _ := FindAllFiles() allFiles, _, _ := FindAllFiles()
serializer := FilesSerializer{c, allFiles} serializer := FilesSerializerNoAssoc{c, allFiles}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"users": serializer.Response(), "files": serializer.Response(),
}) })
} }

View file

@ -10,3 +10,10 @@ func FindAllFiles() ([]common.File, int, error) {
err := db.Find(&files).Error err := db.Find(&files).Error
return files, len(files), err 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
}

View file

@ -1,53 +1,53 @@
package file package file
import ( import (
"time"
"github.com/gin-gonic/gin" "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/common"
) )
type FilesSerializer struct { // File/s Serializers
type FilesSerializerNoAssoc struct {
Ctx *gin.Context Ctx *gin.Context
Files []common.File Files []common.File
} }
func (self *FilesSerializer) Response() []FileResponse { func (self *FilesSerializerNoAssoc) Response() []FileResponseNoAssoc {
response := []FileResponse{} response := []FileResponseNoAssoc{}
for _, File := range self.Files { for _, files := range self.Files {
serializer := FileSerializer{self.Ctx, File} serializer := FileSerializerNoAssoc{self.Ctx, files}
response = append(response, serializer.Response()) response = append(response, serializer.Response())
} }
return response return response
} }
type FileSerializer struct { type FileSerializerNoAssoc struct {
Ctx *gin.Context Ctx *gin.Context
common.File common.File
} }
type FileResponse struct { type FileResponseNoAssoc struct {
Name string `json:"Name"` Name string `json:"Name"`
ID uint `json:"FileID"` ID uint `json:"FileID"`
Path string `json:"Path"` Path string `json:"Path"`
Type string `json:"Type"` //MIME type? Type string `json:"Type"`
Size uint `json:"Size"` Size uint `json:"Size"`
H uint `json:"ImageHeight"` H uint `json:"ImageHeight"`
W uint `json:"ImageWidth"` W uint `json:"ImageWidth"`
Date time.Time `json:"Date"` // Date
} }
func (self *FileSerializer) Response() FileResponse { func (self *FileSerializerNoAssoc) Response() FileResponseNoAssoc {
response := FileResponseNoAssoc{
response := FileResponse{
Name: self.Name, Name: self.Name,
ID: self.ID,
Path: self.Path, Path: self.Path,
Type: self.Type, Type: self.Type,
Size: self.Size, Size: self.Size,
Date: self.Date,
H: self.ImageHeight, H: self.ImageHeight,
W: self.ImageWidth, W: self.ImageWidth,
// Date
} }
return response return response
} }

View file

@ -1 +1,46 @@
package project 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",
})
}

View file

@ -1 +1,28 @@
package project 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
}

View file

@ -1 +1,41 @@
package project 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
}

View file

@ -1 +1,4 @@
package signal package signal
//TODO extend API with signal endpoints

View file

@ -1 +1,3 @@
package signal package signal
//TODO extend API with signal endpoints

View file

@ -1 +1,3 @@
package signal package signal
//TODO extend API with signal endpoints

View file

@ -1 +1,47 @@
package simulation 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",
})
}

View file

@ -1 +1,19 @@
package simulation 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
}

View file

@ -1 +1,43 @@
package simulation 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
}

View file

@ -1 +1,46 @@
package simulationmodel 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",
})
}

View file

@ -1 +1,12 @@
package simulationmodel 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
}

View file

@ -1 +1,52 @@
package simulationmodel 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
}

View file

@ -1 +1,53 @@
package simulator 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",
})
}

View file

@ -1 +1,13 @@
package simulator 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
}

View file

@ -1 +1,52 @@
package simulator 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
}

View file

@ -8,9 +8,9 @@ import (
func UsersRegister(r *gin.RouterGroup) { func UsersRegister(r *gin.RouterGroup) {
r.GET("/", usersReadEp) r.GET("/", usersReadEp)
r.POST("/", userRegistrationEp) r.POST("/", userRegistrationEp)
r.PUT("/:userID", userUpdateEp) r.PUT("/:UserID", userUpdateEp)
r.GET("/:userID", userReadEp) r.GET("/:UserID", userReadEp)
r.DELETE("/:userID", userDeleteEp) r.DELETE("/:UserID", userDeleteEp)
//r.GET("/me", userSelfEp) // TODO: this conflicts with GET /:userID //r.GET("/me", userSelfEp) // TODO: this conflicts with GET /:userID
} }

View file

@ -10,24 +10,3 @@ func FindAllUsers() ([]common.User, int, error) {
err := db.Find(&users).Error err := db.Find(&users).Error
return users, len(users), err 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
}

View file

@ -4,6 +4,9 @@ import (
"github.com/gin-gonic/gin" "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/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 { type UsersSerializer struct {
@ -30,21 +33,21 @@ type UserResponse struct {
Password string `json:"Password"` // XXX: ??? Password string `json:"Password"` // XXX: ???
Role string `json:"Role"` Role string `json:"Role"`
Mail string `json:"Mail"` Mail string `json:"Mail"`
Projects []ProjectResponseNoAssoc Projects []project.ProjectResponseNoAssoc
Simulations []SimulationResponseNoAssoc Simulations []simulation.SimulationResponseNoAssoc
Files []FileResponseNoAssoc Files []file.FileResponseNoAssoc
} }
func (self *UserSerializer) Response() UserResponse { func (self *UserSerializer) Response() UserResponse {
// TODO: maybe all those should be made in one transaction // TODO: maybe all those should be made in one transaction
projects, _, _ := FindUserProjects(&self.User) projects, _, _ := project.FindUserProjects(&self.User)
projectsSerializer := ProjectsSerializerNoAssoc{self.Ctx, projects} projectsSerializer := project.ProjectsSerializerNoAssoc{self.Ctx, projects}
simulations, _, _ := FindUserSimulations(&self.User) simulations, _, _ := simulation.FindUserSimulations(&self.User)
simulationsSerializer := SimulationsSerializerNoAssoc{self.Ctx, simulations} simulationsSerializer := simulation.SimulationsSerializerNoAssoc{self.Ctx, simulations}
files, _, _ := FindUserFiles(&self.User) files, _, _ := file.FindUserFiles(&self.User)
filesSerializer := FilesSerializerNoAssoc{self.Ctx, files} filesSerializer := file.FilesSerializerNoAssoc{self.Ctx, files}
response := UserResponse{ response := UserResponse{
Username: self.Username, Username: self.Username,
@ -58,120 +61,6 @@ func (self *UserSerializer) Response() UserResponse {
return response 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
}

View file

@ -1 +1,46 @@
package visualization 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",
})
}

View file

@ -1 +1,12 @@
package visualization 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
}

View file

@ -1 +1,59 @@
package visualization 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
}

View file

@ -1 +1,3 @@
package widget package widget
// TODO add new API endpoints for widgets

View file

@ -1 +1,14 @@
package widget 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
}

View file

@ -1 +1,60 @@
package widget 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
}

View file

@ -2,7 +2,13 @@ package main
import ( import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common" "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/user"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/visualization"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -17,6 +23,15 @@ func main() {
api := r.Group("/api") api := r.Group("/api")
user.UsersRegister(api.Group("/users")) 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() r.Run()
} }