renaming simulation to scenario

This commit is contained in:
Sonja Happ 2019-07-18 14:35:20 +02:00
parent f0be5cce00
commit b378e8b7c1
21 changed files with 501 additions and 501 deletions

View file

@ -2,7 +2,7 @@ variables:
DEPLOY_USER: deploy DEPLOY_USER: deploy
DEPLOY_HOST: acs-os-fein-website DEPLOY_HOST: acs-os-fein-website
DEPLOY_PATH: /var/www/villas/api/web/ DEPLOY_PATH: /var/www/villas/api/web/
TEST_FOLDER: routes/simulation TEST_FOLDER: routes/scenario
stages: stages:
- prepare - prepare
@ -80,7 +80,7 @@ test:database:
dependencies: dependencies:
- build:backend - build:backend
test:simulation: test:scenario:
stage: test stage: test
tags: tags:
- docker - docker
@ -96,32 +96,32 @@ test:simulation:
- build:backend - build:backend
test:simulationmodel: test:simulationmodel:
extends: test:simulation extends: test:scenario
variables: variables:
TEST_FOLDER: routes/simulationmodel TEST_FOLDER: routes/simulationmodel
test:signal: test:signal:
extends: test:simulation extends: test:scenario
variables: variables:
TEST_FOLDER: routes/signal TEST_FOLDER: routes/signal
test:dashboard: test:dashboard:
extends: test:simulation extends: test:scenario
variables: variables:
TEST_FOLDER: routes/dashboard TEST_FOLDER: routes/dashboard
test:widget: test:widget:
extends: test:simulation extends: test:scenario
variables: variables:
TEST_FOLDER: routes/widget TEST_FOLDER: routes/widget
test:simulator: test:simulator:
extends: test:simulation extends: test:scenario
variables: variables:
TEST_FOLDER: routes/simulator TEST_FOLDER: routes/simulator
test:file: test:file:
extends: test:simulation extends: test:scenario
variables: variables:
TEST_FOLDER: routes/file TEST_FOLDER: routes/file

View file

@ -60,7 +60,7 @@ func DropTables(db *gorm.DB) {
db.DropTableIfExists(&Signal{}) db.DropTableIfExists(&Signal{})
db.DropTableIfExists(&SimulationModel{}) db.DropTableIfExists(&SimulationModel{})
db.DropTableIfExists(&File{}) db.DropTableIfExists(&File{})
db.DropTableIfExists(&Simulation{}) db.DropTableIfExists(&Scenario{})
db.DropTableIfExists(&User{}) db.DropTableIfExists(&User{})
db.DropTableIfExists(&Dashboard{}) db.DropTableIfExists(&Dashboard{})
db.DropTableIfExists(&Widget{}) db.DropTableIfExists(&Widget{})
@ -72,7 +72,7 @@ func MigrateModels(db *gorm.DB) {
db.AutoMigrate(&Signal{}) db.AutoMigrate(&Signal{})
db.AutoMigrate(&SimulationModel{}) db.AutoMigrate(&SimulationModel{})
db.AutoMigrate(&File{}) db.AutoMigrate(&File{})
db.AutoMigrate(&Simulation{}) db.AutoMigrate(&Scenario{})
db.AutoMigrate(&User{}) db.AutoMigrate(&User{})
db.AutoMigrate(&Dashboard{}) db.AutoMigrate(&Dashboard{})
db.AutoMigrate(&Widget{}) db.AutoMigrate(&Widget{})
@ -127,10 +127,10 @@ func DummyPopulateDB(test_db *gorm.DB) {
checkErr(test_db.Create(&file_C).Error) checkErr(test_db.Create(&file_C).Error)
checkErr(test_db.Create(&file_D).Error) checkErr(test_db.Create(&file_D).Error)
simn_A := Simulation{Name: "Simulation_A"} so_A := Scenario{Name: "Scenario_A"}
simn_B := Simulation{Name: "Simulation_B"} so_B := Scenario{Name: "Scenario_B"}
checkErr(test_db.Create(&simn_A).Error) checkErr(test_db.Create(&so_A).Error)
checkErr(test_db.Create(&simn_B).Error) checkErr(test_db.Create(&so_B).Error)
// Hash passwords with bcrypt algorithm // Hash passwords with bcrypt algorithm
var bcryptCost = 10 var bcryptCost = 10
@ -168,19 +168,19 @@ func DummyPopulateDB(test_db *gorm.DB) {
// For `belongs to` use the model with id=1 // For `belongs to` use the model with id=1
// For `has many` use the models with id=1 and id=2 // For `has many` use the models with id=1 and id=2
// User HM Simulations, Simulation HM Users (Many-to-Many) // User HM Scenarios, Scenario HM Users (Many-to-Many)
checkErr(test_db.Model(&simn_A).Association("Users").Append(&usr_A).Error) checkErr(test_db.Model(&so_A).Association("Users").Append(&usr_A).Error)
checkErr(test_db.Model(&simn_A).Association("Users").Append(&usr_B).Error) checkErr(test_db.Model(&so_A).Association("Users").Append(&usr_B).Error)
checkErr(test_db.Model(&simn_B).Association("Users").Append(&usr_A).Error) checkErr(test_db.Model(&so_B).Association("Users").Append(&usr_A).Error)
checkErr(test_db.Model(&simn_B).Association("Users").Append(&usr_B).Error) checkErr(test_db.Model(&so_B).Association("Users").Append(&usr_B).Error)
// Simulation HM SimulationModels // Scenario HM SimulationModels
checkErr(test_db.Model(&simn_A).Association("SimulationModels").Append(&mo_A).Error) checkErr(test_db.Model(&so_A).Association("SimulationModels").Append(&mo_A).Error)
checkErr(test_db.Model(&simn_A).Association("SimulationModels").Append(&mo_B).Error) checkErr(test_db.Model(&so_A).Association("SimulationModels").Append(&mo_B).Error)
// Simulation HM Dashboards // Scenario HM Dashboards
checkErr(test_db.Model(&simn_A).Association("Dashboards").Append(&dab_A).Error) checkErr(test_db.Model(&so_A).Association("Dashboards").Append(&dab_A).Error)
checkErr(test_db.Model(&simn_A).Association("Dashboards").Append(&dab_B).Error) checkErr(test_db.Model(&so_A).Association("Dashboards").Append(&dab_B).Error)
// Dashboard HM Widget // Dashboard HM Widget
checkErr(test_db.Model(&dab_A).Association("Widgets").Append(&widg_A).Error) checkErr(test_db.Model(&dab_A).Association("Widgets").Append(&widg_A).Error)

View file

@ -31,7 +31,7 @@ func TestDummyDBAssociations(t *testing.T) {
var simr Simulator var simr Simulator
var mo SimulationModel var mo SimulationModel
var file File var file File
var simn Simulation var so Scenario
var usr User var usr User
var usrs []User var usrs []User
var dab Dashboard var dab Dashboard
@ -41,7 +41,7 @@ func TestDummyDBAssociations(t *testing.T) {
var mos []SimulationModel var mos []SimulationModel
var files []File var files []File
var files_sm []File var files_sm []File
var simns []Simulation var sos []Scenario
var dabs []Dashboard var dabs []Dashboard
var widgs []Widget var widgs []Widget
@ -52,34 +52,34 @@ func TestDummyDBAssociations(t *testing.T) {
// User Associations // User Associations
a.NoError(db.Model(&usr).Related(&simns, "Simulations").Error) a.NoError(db.Model(&usr).Related(&sos, "Scenarios").Error)
if len(simns) != 2 { if len(sos) != 2 {
a.Fail("User Associations", a.Fail("User Associations",
"Expected to have %v Simulations. Has %v.", 2, len(simns)) "Expected to have %v Scenarios. Has %v.", 2, len(sos))
} }
// Simulation // Scenario
a.NoError(db.Find(&simn, 1).Error, fM("Simulation")) a.NoError(db.Find(&so, 1).Error, fM("Scenario"))
a.EqualValues("Simulation_A", simn.Name) a.EqualValues("Scenario_A", so.Name)
// Simulation Associations // Scenario Associations
a.NoError(db.Model(&simn).Association("Users").Find(&usrs).Error) a.NoError(db.Model(&so).Association("Users").Find(&usrs).Error)
if len(usrs) != 2 { if len(usrs) != 2 {
a.Fail("Simulations Associations", a.Fail("Scenario Associations",
"Expected to have %v Users. Has %v.", 2, len(usrs)) "Expected to have %v Users. Has %v.", 2, len(usrs))
} }
a.NoError(db.Model(&simn).Related(&mos, "SimulationModels").Error) a.NoError(db.Model(&so).Related(&mos, "SimulationModels").Error)
if len(mos) != 2 { if len(mos) != 2 {
a.Fail("Simulation Associations", a.Fail("Scenario Associations",
"Expected to have %v simulation models. Has %v.", 2, len(mos)) "Expected to have %v simulation models. Has %v.", 2, len(mos))
} }
a.NoError(db.Model(&simn).Related(&dabs, "Dashboards").Error) a.NoError(db.Model(&so).Related(&dabs, "Dashboards").Error)
if len(dabs) != 2 { if len(dabs) != 2 {
a.Fail("Simulation Associations", a.Fail("Scenario Associations",
"Expected to have %v Dashboards. Has %v.", 2, len(dabs)) "Expected to have %v Dashboards. Has %v.", 2, len(dabs))
} }

View file

@ -12,26 +12,26 @@ type User struct {
Mail string `gorm:"default:''"` Mail string `gorm:"default:''"`
// Role of user // Role of user
Role string `gorm:"default:'user'"` Role string `gorm:"default:'user'"`
// Simulations to which user has access // Scenarios to which user has access
Simulations []*Simulation `gorm:"many2many:user_simulations"` Scenarios []*Scenario `gorm:"many2many:user_scenarios"`
} }
// Simulation data model // Scenario data model
type Simulation struct { type Scenario struct {
// ID of simulation // ID of scenario
ID uint `gorm:"primary_key;auto_increment"` ID uint `gorm:"primary_key;auto_increment"`
// Name of simulation // Name of scenario
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Running state of simulation // Running state of scenario
Running bool `gorm:"default:false"` Running bool `gorm:"default:false"`
// Start parameters of simulation as JSON string // Start parameters of scenario as JSON string
StartParameters string StartParameters string
// Users that have access to the simulation // Users that have access to the scenario
Users []*User `gorm:"not null;many2many:user_simulations"` Users []*User `gorm:"not null;many2many:user_scenarios"`
// SimulationModels that belong to the simulation // SimulationModels that belong to the scenario
SimulationModels []SimulationModel `gorm:"foreignkey:SimulationID"` SimulationModels []SimulationModel `gorm:"foreignkey:ScenarioID"`
// Dashboards that belong to the simulation // Dashboards that belong to the Scenario
Dashboards []Dashboard `gorm:"foreignkey:SimulationID"` Dashboards []Dashboard `gorm:"foreignkey:ScenarioID"`
} }
// SimulationModel data model // SimulationModel data model
@ -46,8 +46,8 @@ type SimulationModel struct {
InputLength int `gorm:"default:1"` InputLength int `gorm:"default:1"`
// Start parameters of simulation model as JSON string // Start parameters of simulation model as JSON string
StartParameters string StartParameters string
// ID of simulation to which simulation model belongs // ID of Scenario to which simulation model belongs
SimulationID uint ScenarioID uint
// ID of simulator associated with simulation model // ID of simulator associated with simulation model
SimulatorID uint SimulatorID uint
// Mapping of output signals of the simulation model, order of signals is important // Mapping of output signals of the simulation model, order of signals is important
@ -106,8 +106,8 @@ type Dashboard struct {
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Grid of dashboard // Grid of dashboard
Grid int `gorm:"default:15"` Grid int `gorm:"default:15"`
// ID of simulation to which dashboard belongs // ID of scenario to which dashboard belongs
SimulationID uint ScenarioID uint
// Widgets that belong to dashboard // Widgets that belong to dashboard
Widgets []Widget `gorm:"foreignkey:DashboardID"` Widgets []Widget `gorm:"foreignkey:DashboardID"`
} }

View file

@ -7,7 +7,7 @@ type UserResponse struct {
ID uint `json:"ID"` ID uint `json:"ID"`
} }
type SimulationResponse struct { type ScenarioResponse struct {
Name string `json:"Name"` Name string `json:"Name"`
ID uint `json:"ID"` ID uint `json:"ID"`
Running bool `json:"Running"` Running bool `json:"Running"`
@ -19,7 +19,7 @@ type SimulationModelResponse struct {
Name string `json:"Name"` Name string `json:"Name"`
OutputLength int `json:"OutputLength"` OutputLength int `json:"OutputLength"`
InputLength int `json:"InputLength"` InputLength int `json:"InputLength"`
SimulationID uint `json:"SimulationID"` ScenarioID uint `json:"ScenarioID"`
SimulatorID uint `json:"SimulatorID"` SimulatorID uint `json:"SimulatorID"`
StartParams string `json:"StartParams"` StartParams string `json:"StartParams"`
} }
@ -37,10 +37,10 @@ type SimulatorResponse struct {
} }
type DashboardResponse struct { type DashboardResponse struct {
ID uint `json:"ID"` ID uint `json:"ID"`
Name string `json:"Name"` Name string `json:"Name"`
Grid int `json:"Grid"` Grid int `json:"Grid"`
SimulationID uint `json:"SimulationID"` ScenarioID uint `json:"ScenarioID"`
} }
type WidgetResponse struct { type WidgetResponse struct {
@ -93,12 +93,12 @@ type ResponseMsgUser struct {
User UserResponse `json:"user"` User UserResponse `json:"user"`
} }
type ResponseMsgSimulations struct { type ResponseMsgScenarios struct {
Simulations []SimulationResponse `json:"simulations"` Scenarios []ScenarioResponse `json:"scenarios"`
} }
type ResponseMsgSimulation struct { type ResponseMsgScenario struct {
Simulation SimulationResponse `json:"simulation"` Scenario ScenarioResponse `json:"scenario"`
} }
type ResponseMsgSimulationModels struct { type ResponseMsgSimulationModels struct {

View file

@ -15,7 +15,7 @@ import (
type ModelName string type ModelName string
const ModelUser = ModelName("user") const ModelUser = ModelName("user")
const ModelSimulation = ModelName("simulation") const ModelScenario = ModelName("scenario")
const ModelSimulator = ModelName("simulator") const ModelSimulator = ModelName("simulator")
const ModelSimulatorAction = ModelName("simulatoraction") const ModelSimulatorAction = ModelName("simulatoraction")
const ModelDashboard = ModelName("dashboard") const ModelDashboard = ModelName("dashboard")
@ -51,7 +51,7 @@ var _r__ = Permission{Create: false, Read: true, Update: false, Delete: false}
var Roles = RoleActions{ var Roles = RoleActions{
"Admin": { "Admin": {
ModelUser: crud, ModelUser: crud,
ModelSimulation: crud, ModelScenario: crud,
ModelSimulationModel: crud, ModelSimulationModel: crud,
ModelSimulator: crud, ModelSimulator: crud,
ModelSimulatorAction: crud, ModelSimulatorAction: crud,
@ -62,7 +62,7 @@ var Roles = RoleActions{
}, },
"User": { "User": {
ModelUser: __u_, ModelUser: __u_,
ModelSimulation: crud, ModelScenario: crud,
ModelSimulationModel: crud, ModelSimulationModel: crud,
ModelSimulator: _r__, ModelSimulator: _r__,
ModelSimulatorAction: _ru_, ModelSimulatorAction: _ru_,
@ -72,7 +72,7 @@ var Roles = RoleActions{
ModelFile: crud, ModelFile: crud,
}, },
"Guest": { "Guest": {
ModelSimulation: _r__, ModelScenario: _r__,
ModelSimulationModel: _r__, ModelSimulationModel: _r__,
ModelDashboard: _r__, ModelDashboard: _r__,
ModelWidget: _r__, ModelWidget: _r__,

View file

@ -40,40 +40,40 @@ func (self *UserSerializer) Response(assoc bool) UserResponse {
// TODO: maybe all those should be made in one transaction // TODO: maybe all those should be made in one transaction
//simulations, _, _ := simulation.FindUserSimulations(&self.User) //scenarios, _, _ := scenario.FindUserScenarios(&self.User)
//simulationsSerializer := //scenariosSerializer :=
// SimulationsSerializer{self.Ctx, simulations} // ScenariosSerializer{self.Ctx, scenarios}
// Add the associated models to the response // Add the associated models to the response
//response.Simulations = simulationsSerializer.Response() //response.Scenarios = scenariosSerializer.Response()
} }
return response return response
} }
// Simulation/s Serializers // Scenario/s Serializers
type SimulationsSerializer struct { type ScenariosSerializer struct {
Ctx *gin.Context Ctx *gin.Context
Simulations []Simulation Scenarios []Scenario
} }
func (self *SimulationsSerializer) Response() []SimulationResponse { func (self *ScenariosSerializer) Response() []ScenarioResponse {
response := []SimulationResponse{} response := []ScenarioResponse{}
for _, simulation := range self.Simulations { for _, so := range self.Scenarios {
serializer := SimulationSerializer{self.Ctx, simulation} serializer := ScenarioSerializer{self.Ctx, so}
response = append(response, serializer.Response()) response = append(response, serializer.Response())
} }
return response return response
} }
type SimulationSerializer struct { type ScenarioSerializer struct {
Ctx *gin.Context Ctx *gin.Context
Simulation Scenario
} }
func (self *SimulationSerializer) Response() SimulationResponse { func (self *ScenarioSerializer) Response() ScenarioResponse {
response := SimulationResponse{ response := ScenarioResponse{
Name: self.Name, Name: self.Name,
ID: self.ID, ID: self.ID,
Running: self.Running, Running: self.Running,
@ -109,7 +109,7 @@ func (self *SimulationModelSerializer) Response() SimulationModelResponse {
Name: self.Name, Name: self.Name,
OutputLength: self.OutputLength, OutputLength: self.OutputLength,
InputLength: self.InputLength, InputLength: self.InputLength,
SimulationID: self.SimulationID, ScenarioID: self.ScenarioID,
SimulatorID: self.SimulatorID, SimulatorID: self.SimulatorID,
StartParams: self.StartParameters, StartParams: self.StartParameters,
} }
@ -175,10 +175,10 @@ type DashboardSerializer struct {
func (self *DashboardSerializer) Response() DashboardResponse { func (self *DashboardSerializer) Response() DashboardResponse {
response := DashboardResponse{ response := DashboardResponse{
Name: self.Name, Name: self.Name,
Grid: self.Grid, Grid: self.Grid,
SimulationID: self.SimulationID, ScenarioID: self.ScenarioID,
ID: self.ID, ID: self.ID,
} }
return response return response
} }

View file

@ -6,7 +6,7 @@ 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/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
) )
func RegisterDashboardEndpoints(r *gin.RouterGroup) { func RegisterDashboardEndpoints(r *gin.RouterGroup) {
@ -19,20 +19,20 @@ func RegisterDashboardEndpoints(r *gin.RouterGroup) {
} }
// getDashboards godoc // getDashboards godoc
// @Summary Get all dashboards of simulation // @Summary Get all dashboards of scenario
// @ID getDashboards // @ID getDashboards
// @Produce json // @Produce json
// @Tags dashboards // @Tags dashboards
// @Success 200 {array} common.DashboardResponse "Array of dashboards to which belong to simulation" // @Success 200 {array} common.DashboardResponse "Array of dashboards to which belong to scenario"
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID query int true "Simulation ID" // @Param scenarioID query int true "Scenario ID"
// @Router /dashboards [get] // @Router /dashboards [get]
func getDashboards(c *gin.Context) { func getDashboards(c *gin.Context) {
ok, sim := simulation.CheckPermissions(c, common.Read, "query", -1) ok, sim := scenario.CheckPermissions(c, common.Read, "query", -1)
if !ok { if !ok {
return return
} }
@ -51,12 +51,12 @@ func getDashboards(c *gin.Context) {
} }
// addDashboard godoc // addDashboard godoc
// @Summary Add a dashboard to a simulation // @Summary Add a dashboard to a scenario
// @ID addDashboard // @ID addDashboard
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Tags dashboards // @Tags dashboards
// @Param inputDab body common.DashboardResponse true "Dashboard to be added incl. ID of simulation" // @Param inputDab body common.DashboardResponse true "Dashboard to be added incl. ID of Scenario"
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
@ -75,13 +75,13 @@ func addDashboard(c *gin.Context) {
return return
} }
ok, _ := simulation.CheckPermissions(c, common.Create, "body", int(newDab.SimulationID)) ok, _ := scenario.CheckPermissions(c, common.Create, "body", int(newDab.ScenarioID))
if !ok { if !ok {
return return
} }
// add dashboard to DB and add association to simulation // add dashboard to DB and add association to scenario
err = newDab.addToSimulation() err = newDab.addToScenario()
if common.ProvideErrorResponse(c, err) == false { if common.ProvideErrorResponse(c, err) == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "OK.", "message": "OK.",

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"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/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
) )
type Dashboard struct { type Dashboard struct {
@ -26,10 +26,10 @@ func (d *Dashboard) ByID(id uint) error {
return nil return nil
} }
func (d *Dashboard) addToSimulation() error { func (d *Dashboard) addToScenario() error {
db := common.GetDB() db := common.GetDB()
var sim simulation.Simulation var sim scenario.Scenario
err := sim.ByID(d.SimulationID) err := sim.ByID(d.ScenarioID)
if err != nil { if err != nil {
return err return err
} }
@ -40,7 +40,7 @@ func (d *Dashboard) addToSimulation() error {
return err return err
} }
// associate dashboard with simulation // associate dashboard with scenario
err = db.Model(&sim).Association("Dashboards").Append(d).Error err = db.Model(&sim).Association("Dashboards").Append(d).Error
return err return err
@ -61,13 +61,13 @@ func (d *Dashboard) update(modifiedDab Dashboard) error {
func (d *Dashboard) delete() error { func (d *Dashboard) delete() error {
db := common.GetDB() db := common.GetDB()
var sim simulation.Simulation var sim scenario.Scenario
err := sim.ByID(d.SimulationID) err := sim.ByID(d.ScenarioID)
if err != nil { if err != nil {
return err return err
} }
// remove association between Dashboard and Simulation // remove association between Dashboard and Scenario
// Dashboard itself is not deleted from DB, it remains as "dangling" // Dashboard itself is not deleted from DB, it remains as "dangling"
err = db.Model(&sim).Association("Dashboards").Delete(d).Error err = db.Model(&sim).Association("Dashboards").Delete(d).Error

View file

@ -2,13 +2,13 @@ package dashboard
import ( import (
"fmt" "fmt"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
"net/http" "net/http"
"strconv" "strconv"
"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/simulation"
) )
func CheckPermissions(c *gin.Context, operation common.CRUD, dabIDSource string, dabIDBody int) (bool, Dashboard) { func CheckPermissions(c *gin.Context, operation common.CRUD, dabIDSource string, dabIDBody int) (bool, Dashboard) {
@ -49,7 +49,7 @@ func CheckPermissions(c *gin.Context, operation common.CRUD, dabIDSource string,
return false, dab return false, dab
} }
ok, _ := simulation.CheckPermissions(c, operation, "body", int(dab.SimulationID)) ok, _ := scenario.CheckPermissions(c, operation, "body", int(dab.ScenarioID))
if !ok { if !ok {
return false, dab return false, dab
} }

View file

@ -27,45 +27,45 @@ var msgOK = common.ResponseMsg{
} }
var dabA = common.DashboardResponse{ var dabA = common.DashboardResponse{
ID: 1, ID: 1,
Name: "Dashboard_A", Name: "Dashboard_A",
Grid: 15, Grid: 15,
SimulationID: 1, ScenarioID: 1,
} }
var dabB = common.DashboardResponse{ var dabB = common.DashboardResponse{
ID: 2, ID: 2,
Name: "Dashboard_B", Name: "Dashboard_B",
Grid: 15, Grid: 15,
SimulationID: 1, ScenarioID: 1,
} }
var dabC = common.Dashboard{ var dabC = common.Dashboard{
ID: 3, ID: 3,
Name: "Dashboard_C", Name: "Dashboard_C",
Grid: 99, Grid: 99,
SimulationID: 1, ScenarioID: 1,
} }
var dabCupdated = common.Dashboard{ var dabCupdated = common.Dashboard{
ID: dabC.ID, ID: dabC.ID,
Name: "Dashboard_CUpdated", Name: "Dashboard_CUpdated",
SimulationID: dabC.SimulationID, ScenarioID: dabC.ScenarioID,
Grid: dabC.Grid, Grid: dabC.Grid,
} }
var dabC_response = common.DashboardResponse{ var dabC_response = common.DashboardResponse{
ID: dabC.ID, ID: dabC.ID,
Name: dabC.Name, Name: dabC.Name,
Grid: dabC.Grid, Grid: dabC.Grid,
SimulationID: dabC.SimulationID, ScenarioID: dabC.ScenarioID,
} }
var dabC_responseUpdated = common.DashboardResponse{ var dabC_responseUpdated = common.DashboardResponse{
ID: dabCupdated.ID, ID: dabCupdated.ID,
Name: dabCupdated.Name, Name: dabCupdated.Name,
Grid: dabCupdated.Grid, Grid: dabCupdated.Grid,
SimulationID: dabCupdated.SimulationID, ScenarioID: dabCupdated.ScenarioID,
} }
var myDashboards = []common.DashboardResponse{ var myDashboards = []common.DashboardResponse{
@ -140,22 +140,22 @@ func TestEndpoints(t *testing.T) {
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200) token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
// test GET models // test GET dashboards
common.TestEndpoint(t, router, token, "/api/dashboards?simulationID=1", "GET", nil, 200, string(msgDashboardsjson)) common.TestEndpoint(t, router, token, "/api/dashboards?scenarioID=1", "GET", nil, 200, string(msgDashboardsjson))
// test POST models // test POST dashboards
common.TestEndpoint(t, router, token, "/api/dashboards", "POST", dabCjson, 200, string(msgOKjson)) common.TestEndpoint(t, router, token, "/api/dashboards", "POST", dabCjson, 200, string(msgOKjson))
// test GET models/:ModelID to check if previous POST worked correctly // test GET dashboards/:dashboardID to check if previous POST worked correctly
common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, string(msgDabjson)) common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, string(msgDabjson))
// test PUT models/:ModelID // test PUT dashboards/:dashboardID
common.TestEndpoint(t, router, token, "/api/dashboards/3", "PUT", dabCupdatedjson, 200, string(msgOKjson)) common.TestEndpoint(t, router, token, "/api/dashboards/3", "PUT", dabCupdatedjson, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, string(msgDabupdatedjson)) common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, string(msgDabupdatedjson))
// test DELETE models/:ModelID // test DELETE dashboards/:dashboardID
common.TestEndpoint(t, router, token, "/api/dashboards/3", "DELETE", nil, 200, string(msgOKjson)) common.TestEndpoint(t, router, token, "/api/dashboards/3", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/dashboards?simulationID=1", "GET", nil, 200, string(msgDashboardsjson)) common.TestEndpoint(t, router, token, "/api/dashboards?scenarioID=1", "GET", nil, 200, string(msgDashboardsjson))
// TODO add testing for other return codes // TODO add testing for other return codes

View file

@ -1,4 +1,4 @@
package simulation package scenario
import ( import (
"net/http" "net/http"
@ -9,29 +9,29 @@ import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
) )
func RegisterSimulationEndpoints(r *gin.RouterGroup) { func RegisterScenarioEndpoints(r *gin.RouterGroup) {
r.GET("", getSimulations) r.GET("", getScenarios)
r.POST("", addSimulation) r.POST("", addScenario)
r.PUT("/:simulationID", updateSimulation) r.PUT("/:scenarioID", updateScenario)
r.GET("/:simulationID", getSimulation) r.GET("/:scenarioID", getScenario)
r.DELETE("/:simulationID", deleteSimulation) r.DELETE("/:scenarioID", deleteScenario)
r.GET("/:simulationID/users", getUsersOfSimulation) r.GET("/:scenarioID/users", getUsersOfScenario)
r.PUT("/:simulationID/user", addUserToSimulation) r.PUT("/:scenarioID/user", addUserToScenario)
r.DELETE("/:simulationID/user", deleteUserFromSimulation) r.DELETE("/:scenarioID/user", deleteUserFromScenario)
} }
// getSimulations godoc // getScenarios godoc
// @Summary Get all simulations // @Summary Get all scenarios
// @ID getSimulations // @ID getScenarios
// @Produce json // @Produce json
// @Tags simulations // @Tags scenarios
// @Success 200 {array} common.SimulationResponse "Array of simulations to which user has access" // @Success 200 {array} common.ScenarioResponse "Array of scenarios to which user has access"
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Router /simulations [get] // @Router /scenarios [get]
func getSimulations(c *gin.Context) { func getScenarios(c *gin.Context) {
ok, _ := CheckPermissions(c, common.Read, "none", -1) ok, _ := CheckPermissions(c, common.Read, "none", -1)
if !ok { if !ok {
@ -48,42 +48,42 @@ func getSimulations(c *gin.Context) {
return return
} }
// get all simulations for the user who issues the request // get all scenarios for the user who issues the request
db := common.GetDB() db := common.GetDB()
var simulations []common.Simulation var scenarios []common.Scenario
if userRole == "Admin" { // Admin can see all simulations if userRole == "Admin" { // Admin can see all scenarios
err = db.Order("ID asc").Find(&simulations).Error err = db.Order("ID asc").Find(&scenarios).Error
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
} else { // User or Guest roles see only their simulations } else { // User or Guest roles see only their scenarios
err = db.Order("ID asc").Model(&u).Related(&simulations, "Simulations").Error err = db.Order("ID asc").Model(&u).Related(&scenarios, "Scenarios").Error
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
} }
serializer := common.SimulationsSerializer{c, simulations} serializer := common.ScenariosSerializer{c, scenarios}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"simulations": serializer.Response(), "scenarios": serializer.Response(),
}) })
} }
// addSimulation godoc // addScenario godoc
// @Summary Add a simulation // @Summary Add a scenario
// @ID addSimulation // @ID addScenario
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Tags simulations // @Tags scenarios
// @Param inputSimulation body common.SimulationResponse true "Simulation to be added" // @Param inputScenario body common.ScenarioResponse true "Scenario to be added"
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Router /simulations [post] // @Router /scenarios [post]
func addSimulation(c *gin.Context) { func addScenario(c *gin.Context) {
ok, _ := CheckPermissions(c, common.Create, "none", -1) ok, _ := CheckPermissions(c, common.Create, "none", -1)
if !ok { if !ok {
@ -98,8 +98,8 @@ func addSimulation(c *gin.Context) {
return return
} }
var sim Simulation var so Scenario
err = c.BindJSON(&sim) err = c.BindJSON(&so)
if err != nil { if err != nil {
errormsg := "Bad request. Error binding form data to JSON: " + err.Error() errormsg := "Bad request. Error binding form data to JSON: " + err.Error()
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
@ -108,14 +108,14 @@ func addSimulation(c *gin.Context) {
return return
} }
// save new simulation to DB // save new scenario to DB
err = sim.save() err = so.save()
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
// add user to new simulation // add user to new scenario
err = sim.addUser(&(u.User)) err = so.addUser(&(u.User))
if common.ProvideErrorResponse(c, err) == false { if common.ProvideErrorResponse(c, err) == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "OK.", "message": "OK.",
@ -123,29 +123,29 @@ func addSimulation(c *gin.Context) {
} }
} }
// updateSimulation godoc // updateScenario godoc
// @Summary Update a simulation // @Summary Update a scenario
// @ID updateSimulation // @ID updateScenario
// @Tags simulations // @Tags scenarios
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param inputSimulation body common.SimulationResponse true "Simulation to be updated" // @Param inputScenario body common.ScenarioResponse true "Scenario to be updated"
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID path int true "Simulation ID" // @Param scenarioID path int true "Scenario ID"
// @Router /simulations/{simulationID} [put] // @Router /scenarios/{scenarioID} [put]
func updateSimulation(c *gin.Context) { func updateScenario(c *gin.Context) {
ok, sim := CheckPermissions(c, common.Update, "path", -1) ok, so := CheckPermissions(c, common.Update, "path", -1)
if !ok { if !ok {
return return
} }
var modifiedSim Simulation var modifiedSo Scenario
err := c.BindJSON(&modifiedSim) err := c.BindJSON(&modifiedSo)
if err != nil { if err != nil {
errormsg := "Bad request. Error binding form data to JSON: " + err.Error() errormsg := "Bad request. Error binding form data to JSON: " + err.Error()
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
@ -154,7 +154,7 @@ func updateSimulation(c *gin.Context) {
return return
} }
err = sim.update(modifiedSim) err = so.update(modifiedSo)
if common.ProvideErrorResponse(c, err) == false { if common.ProvideErrorResponse(c, err) == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "OK.", "message": "OK.",
@ -162,51 +162,51 @@ func updateSimulation(c *gin.Context) {
} }
} }
// getSimulation godoc // getScenario godoc
// @Summary Get simulation // @Summary Get scenario
// @ID getSimulation // @ID getScenario
// @Produce json // @Produce json
// @Tags simulations // @Tags scenarios
// @Success 200 {object} common.SimulationResponse "Simulation requested by user" // @Success 200 {object} common.ScenarioResponse "Scenario requested by user"
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID path int true "Simulation ID" // @Param scenarioID path int true "Scenario ID"
// @Router /simulations/{simulationID} [get] // @Router /scenarios/{scenarioID} [get]
func getSimulation(c *gin.Context) { func getScenario(c *gin.Context) {
ok, sim := CheckPermissions(c, common.Read, "path", -1) ok, so := CheckPermissions(c, common.Read, "path", -1)
if !ok { if !ok {
return return
} }
serializer := common.SimulationSerializer{c, sim.Simulation} serializer := common.ScenarioSerializer{c, so.Scenario}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"simulation": serializer.Response(), "scenario": serializer.Response(),
}) })
} }
// deleteSimulation godoc // deleteScenario godoc
// @Summary Delete a simulation // @Summary Delete a scenario
// @ID deleteSimulation // @ID deleteScenario
// @Tags simulations // @Tags scenarios
// @Produce json // @Produce json
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID path int true "Simulation ID" // @Param scenarioID path int true "Scenario ID"
// @Router /simulations/{simulationID} [delete] // @Router /scenarios/{scenarioID} [delete]
func deleteSimulation(c *gin.Context) { func deleteScenario(c *gin.Context) {
ok, sim := CheckPermissions(c, common.Delete, "path", -1) ok, so := CheckPermissions(c, common.Delete, "path", -1)
if !ok { if !ok {
return return
} }
err := sim.delete() err := so.delete()
if common.ProvideErrorResponse(c, err) == false { if common.ProvideErrorResponse(c, err) == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "OK.", "message": "OK.",
@ -214,27 +214,27 @@ func deleteSimulation(c *gin.Context) {
} }
} }
// getUsersOfSimulation godoc // getUsersOfScenario godoc
// @Summary Get users of simulation // @Summary Get users of a scenario
// @ID getUsersOfSimulation // @ID getUsersOfScenario
// @Produce json // @Produce json
// @Tags simulations // @Tags scenarios
// @Success 200 {array} common.UserResponse "Array of users that have access to the simulation" // @Success 200 {array} common.UserResponse "Array of users that have access to the scenario"
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID path int true "Simulation ID" // @Param scenarioID path int true "Scenario ID"
// @Router /simulations/{simulationID}/users/ [get] // @Router /scenarios/{scenarioID}/users/ [get]
func getUsersOfSimulation(c *gin.Context) { func getUsersOfScenario(c *gin.Context) {
ok, sim := CheckPermissions(c, common.Read, "path", -1) ok, so := CheckPermissions(c, common.Read, "path", -1)
if !ok { if !ok {
return return
} }
// Find all users of simulation // Find all users of scenario
allUsers, _, err := sim.getUsers() allUsers, _, err := so.getUsers()
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
@ -245,22 +245,22 @@ func getUsersOfSimulation(c *gin.Context) {
}) })
} }
// addUserToSimulation godoc // addUserToScenario godoc
// @Summary Add a user to a a simulation // @Summary Add a user to a a scenario
// @ID addUserToSimulation // @ID addUserToScenario
// @Tags simulations // @Tags scenarios
// @Produce json // @Produce json
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID path int true "Simulation ID" // @Param scenarioID path int true "Scenario ID"
// @Param username query string true "User name" // @Param username query string true "User name"
// @Router /simulations/{simulationID}/user [put] // @Router /scenarios/{scenarioID}/user [put]
func addUserToSimulation(c *gin.Context) { func addUserToScenario(c *gin.Context) {
ok, sim := CheckPermissions(c, common.Update, "path", -1) ok, so := CheckPermissions(c, common.Update, "path", -1)
if !ok { if !ok {
return return
} }
@ -273,7 +273,7 @@ func addUserToSimulation(c *gin.Context) {
return return
} }
err = sim.addUser(&(u.User)) err = so.addUser(&(u.User))
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
@ -283,29 +283,29 @@ func addUserToSimulation(c *gin.Context) {
}) })
} }
// deleteUserFromSimulation godoc // deleteUserFromScenario godoc
// @Summary Delete a user from a simulation // @Summary Delete a user from a scenario
// @ID deleteUserFromSimulation // @ID deleteUserFromScenario
// @Tags simulations // @Tags scenarios
// @Produce json // @Produce json
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID path int true "Simulation ID" // @Param scenarioID path int true "Scenario ID"
// @Param username query string true "User name" // @Param username query string true "User name"
// @Router /simulations/{simulationID}/user [delete] // @Router /scenarios/{scenarioID}/user [delete]
func deleteUserFromSimulation(c *gin.Context) { func deleteUserFromScenario(c *gin.Context) {
ok, sim := CheckPermissions(c, common.Update, "path", -1) ok, so := CheckPermissions(c, common.Update, "path", -1)
if !ok { if !ok {
return return
} }
username := c.Request.URL.Query().Get("username") username := c.Request.URL.Query().Get("username")
err := sim.deleteUser(username) err := so.deleteUser(username)
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }

View file

@ -1,4 +1,4 @@
package simulation package scenario
import ( import (
"fmt" "fmt"
@ -7,46 +7,46 @@ import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
) )
type Simulation struct { type Scenario struct {
common.Simulation common.Scenario
} }
func (s *Simulation) ByID(id uint) error { func (s *Scenario) ByID(id uint) error {
db := common.GetDB() db := common.GetDB()
err := db.Find(s, id).Error err := db.Find(s, id).Error
if err != nil { if err != nil {
return fmt.Errorf("simulation with id=%v does not exist", id) return fmt.Errorf("scenario with id=%v does not exist", id)
} }
return nil return nil
} }
func (s *Simulation) getUsers() ([]common.User, int, error) { func (s *Scenario) getUsers() ([]common.User, int, error) {
db := common.GetDB() db := common.GetDB()
var users []common.User var users []common.User
err := db.Order("ID asc").Model(s).Related(&users, "Users").Error err := db.Order("ID asc").Model(s).Related(&users, "Users").Error
return users, len(users), err return users, len(users), err
} }
func (s *Simulation) save() error { func (s *Scenario) save() error {
db := common.GetDB() db := common.GetDB()
err := db.Create(s).Error err := db.Create(s).Error
return err return err
} }
func (s *Simulation) update(modifiedSimulation Simulation) error { func (s *Scenario) update(modifiedScenario Scenario) error {
db := common.GetDB() db := common.GetDB()
err := db.Model(s).Update(modifiedSimulation).Error err := db.Model(s).Update(modifiedScenario).Error
return err return err
} }
func (s *Simulation) addUser(u *common.User) error { func (s *Scenario) addUser(u *common.User) error {
db := common.GetDB() db := common.GetDB()
err := db.Model(s).Association("Users").Append(u).Error err := db.Model(s).Association("Users").Append(u).Error
return err return err
} }
func (s *Simulation) deleteUser(username string) error { func (s *Scenario) deleteUser(username string) error {
db := common.GetDB() db := common.GetDB()
var deletedUser user.User var deletedUser user.User
@ -58,27 +58,27 @@ func (s *Simulation) deleteUser(username string) error {
no_users := db.Model(s).Association("Users").Count() no_users := db.Model(s).Association("Users").Count()
if no_users > 1 { if no_users > 1 {
// remove user from simulation // remove user from scenario
err = db.Model(s).Association("Users").Delete(&deletedUser.User).Error err = db.Model(s).Association("Users").Delete(&deletedUser.User).Error
if err != nil { if err != nil {
return err return err
} }
// remove simulation from user // remove scenario from user
err = db.Model(&deletedUser.User).Association("Simulations").Delete(s).Error err = db.Model(&deletedUser.User).Association("Scenarios").Delete(s).Error
if err != nil { if err != nil {
return err return err
} }
} else { } else {
return fmt.Errorf("cannot delete last user from simulation without deleting simulation itself, doing nothing") return fmt.Errorf("cannot delete last user from scenario without deleting scenario itself, doing nothing")
} }
return nil return nil
} }
func (s *Simulation) delete() error { func (s *Scenario) delete() error {
db := common.GetDB() db := common.GetDB()
// delete simulation from all users and vice versa // delete scenario from all users and vice versa
users, no_users, err := s.getUsers() users, no_users, err := s.getUsers()
if err != nil { if err != nil {
@ -87,23 +87,23 @@ func (s *Simulation) delete() error {
if no_users > 0 { if no_users > 0 {
for _, u := range users { for _, u := range users {
// remove user from simulation // remove user from scenario
err = db.Model(s).Association("Users").Delete(&u).Error err = db.Model(s).Association("Users").Delete(&u).Error
if err != nil { if err != nil {
return err return err
} }
// remove simulation from user // remove scenario from user
err = db.Model(&u).Association("Simulations").Delete(s).Error err = db.Model(&u).Association("Scenarios").Delete(s).Error
if err != nil { if err != nil {
return err return err
} }
} }
} }
// Simulation is not deleted from DB, only associations with users are removed // Scenario is not deleted from DB, only associations with users are removed
// Simulation remains "dangling" in DB // Scenario remains "dangling" in DB
// Delete simulation // Delete scenario
//err = db.Delete(s).Error //err = db.Delete(s).Error
//if err != nil { //if err != nil {
// return err // return err
@ -112,7 +112,7 @@ func (s *Simulation) delete() error {
return nil return nil
} }
func (s *Simulation) checkAccess(userID uint, userRole string) bool { func (s *Scenario) checkAccess(userID uint, userRole string) bool {
if userRole == "Admin" { if userRole == "Admin" {
return true return true

View file

@ -1,4 +1,4 @@
package simulation package scenario
import ( import (
"fmt" "fmt"
@ -10,62 +10,62 @@ import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
) )
func CheckPermissions(c *gin.Context, operation common.CRUD, simIDSource string, simIDBody int) (bool, Simulation) { func CheckPermissions(c *gin.Context, operation common.CRUD, simIDSource string, simIDBody int) (bool, Scenario) {
var sim Simulation var so Scenario
err := common.ValidateRole(c, common.ModelSimulation, operation) err := common.ValidateRole(c, common.ModelScenario, operation)
if err != nil { if err != nil {
c.JSON(http.StatusUnprocessableEntity, "Access denied (role validation failed).") c.JSON(http.StatusUnprocessableEntity, "Access denied (role validation failed).")
return false, sim return false, so
} }
if operation == common.Create || (operation == common.Read && simIDSource == "none") { if operation == common.Create || (operation == common.Read && simIDSource == "none") {
return true, sim return true, so
} }
var simID int var simID int
if simIDSource == "path" { if simIDSource == "path" {
simID, err = strconv.Atoi(c.Param("simulationID")) simID, err = strconv.Atoi(c.Param("scenarioID"))
if err != nil { if err != nil {
errormsg := fmt.Sprintf("Bad request. No or incorrect format of simulationID path parameter") errormsg := fmt.Sprintf("Bad request. No or incorrect format of scenarioID path parameter")
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": errormsg, "error": errormsg,
}) })
return false, sim return false, so
} }
} else if simIDSource == "query" { } else if simIDSource == "query" {
simID, err = strconv.Atoi(c.Request.URL.Query().Get("simulationID")) simID, err = strconv.Atoi(c.Request.URL.Query().Get("scenarioID"))
if err != nil { if err != nil {
errormsg := fmt.Sprintf("Bad request. No or incorrect format of simulationID query parameter") errormsg := fmt.Sprintf("Bad request. No or incorrect format of scenarioID query parameter")
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": errormsg, "error": errormsg,
}) })
return false, sim return false, so
} }
} else if simIDSource == "body" { } else if simIDSource == "body" {
simID = simIDBody simID = simIDBody
} else { } else {
errormsg := fmt.Sprintf("Bad request. The following source of your simulation ID is not valid: %s", simIDSource) errormsg := fmt.Sprintf("Bad request. The following source of your scenario ID is not valid: %s", simIDSource)
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": errormsg, "error": errormsg,
}) })
return false, sim return false, so
} }
userID, _ := c.Get(common.UserIDCtx) userID, _ := c.Get(common.UserIDCtx)
userRole, _ := c.Get(common.UserRoleCtx) userRole, _ := c.Get(common.UserRoleCtx)
err = sim.ByID(uint(simID)) err = so.ByID(uint(simID))
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return false, sim return false, so
} }
if sim.checkAccess(userID.(uint), userRole.(string)) == false { if so.checkAccess(userID.(uint), userRole.(string)) == false {
c.JSON(http.StatusUnprocessableEntity, "Access denied (for simulation ID).") c.JSON(http.StatusUnprocessableEntity, "Access denied (for scenario ID).")
return false, sim return false, so
} }
return true, sim return true, so
} }

View file

@ -0,0 +1,180 @@
package scenario
import (
"encoding/json"
"testing"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
var token string
type credentials struct {
Username string `json:"username"`
Password string `json:"password"`
}
var cred = credentials{
Username: "User_A",
Password: "abc123",
}
var msgOK = common.ResponseMsg{
Message: "OK.",
}
var user_A = common.UserResponse{
Username: "User_A",
Role: "User",
Mail: "",
ID: 2,
}
var user_B = common.UserResponse{
Username: "User_B",
Role: "User",
Mail: "",
ID: 3,
}
var myUsers = []common.UserResponse{
user_A,
user_B,
}
var myUserA = []common.UserResponse{
user_A,
}
var msgUsers = common.ResponseMsgUsers{
Users: myUsers,
}
var msgUserA = common.ResponseMsgUsers{
Users: myUserA,
}
var scenarioA = common.ScenarioResponse{
Name: "Scenario_A",
ID: 1,
Running: false,
}
var scenarioB = common.ScenarioResponse{
Name: "Scenario_B",
ID: 2,
Running: false,
}
var scenarioC = common.Scenario{
Name: "Scenario_C",
Running: false,
StartParameters: "test",
}
var scenarioC_response = common.ScenarioResponse{
ID: 3,
Name: scenarioC.Name,
Running: scenarioC.Running,
StartParams: scenarioC.StartParameters,
}
var myScenarios = []common.ScenarioResponse{
scenarioA,
scenarioB,
}
var msgScenarios = common.ResponseMsgScenarios{
Scenarios: myScenarios,
}
var msgScenario = common.ResponseMsgScenario{
Scenario: scenarioC_response,
}
// Test /scenarios endpoints
func TestScenarioEndpoints(t *testing.T) {
db := common.DummyInitDB()
defer db.Close()
common.DummyPopulateDB(db)
router := gin.Default()
api := router.Group("/api")
// All endpoints require authentication except when someone wants to
// login (POST /authenticate)
user.VisitorAuthenticate(api.Group("/authenticate"))
api.Use(user.Authentication(true))
RegisterScenarioEndpoints(api.Group("/scenarios"))
credjson, err := json.Marshal(cred)
msgOKjson, err := json.Marshal(msgOK)
if err != nil {
panic(err)
}
msgUsersjson, err := json.Marshal(msgUsers)
if err != nil {
panic(err)
}
msgUserAjson, err := json.Marshal(msgUserA)
if err != nil {
panic(err)
}
msgScenariosjson, err := json.Marshal(msgScenarios)
if err != nil {
panic(err)
}
msgScenariojson, err := json.Marshal(msgScenario)
if err != nil {
panic(err)
}
scenarioCjson, err := json.Marshal(scenarioC)
if err != nil {
panic(err)
}
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
// test GET scenarios/
common.TestEndpoint(t, router, token, "/api/scenarios", "GET", nil, 200, string(msgScenariosjson))
// test POST scenarios/
common.TestEndpoint(t, router, token, "/api/scenarios", "POST", scenarioCjson, 200, string(msgOKjson))
// test GET scenarios/:ScenarioID
common.TestEndpoint(t, router, token, "/api/scenarios/3", "GET", nil, 200, string(msgScenariojson))
// test DELETE scenarios/:ScenarioID
common.TestEndpoint(t, router, token, "/api/scenarios/3", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/scenarios", "GET", nil, 200, string(msgScenariosjson))
// test GET scenarios/:ScenarioID/users
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, string(msgUsersjson))
// test DELETE scenarios/:ScenarioID/user
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_B", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, string(msgUserAjson))
// test PUT scenarios/:ScenarioID/user
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_B", "PUT", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, string(msgUsersjson))
// test DELETE scenarios/:ScenarioID/user for logged in user User_A
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_A", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 422, "\"Access denied (for scenario ID).\"")
// TODO add tests for other return codes
}

View file

@ -1,180 +0,0 @@
package simulation
import (
"encoding/json"
"testing"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
var token string
type credentials struct {
Username string `json:"username"`
Password string `json:"password"`
}
var cred = credentials{
Username: "User_A",
Password: "abc123",
}
var msgOK = common.ResponseMsg{
Message: "OK.",
}
var user_A = common.UserResponse{
Username: "User_A",
Role: "User",
Mail: "",
ID: 2,
}
var user_B = common.UserResponse{
Username: "User_B",
Role: "User",
Mail: "",
ID: 3,
}
var myUsers = []common.UserResponse{
user_A,
user_B,
}
var myUserA = []common.UserResponse{
user_A,
}
var msgUsers = common.ResponseMsgUsers{
Users: myUsers,
}
var msgUserA = common.ResponseMsgUsers{
Users: myUserA,
}
var simulationA = common.SimulationResponse{
Name: "Simulation_A",
ID: 1,
Running: false,
}
var simulationB = common.SimulationResponse{
Name: "Simulation_B",
ID: 2,
Running: false,
}
var simulationC = common.Simulation{
Name: "Simulation_C",
Running: false,
StartParameters: "test",
}
var simulationC_response = common.SimulationResponse{
ID: 3,
Name: simulationC.Name,
Running: simulationC.Running,
StartParams: simulationC.StartParameters,
}
var mySimulations = []common.SimulationResponse{
simulationA,
simulationB,
}
var msgSimulations = common.ResponseMsgSimulations{
Simulations: mySimulations,
}
var msgSimulation = common.ResponseMsgSimulation{
Simulation: simulationC_response,
}
// Test /simulation endpoints
func TestSimulationEndpoints(t *testing.T) {
db := common.DummyInitDB()
defer db.Close()
common.DummyPopulateDB(db)
router := gin.Default()
api := router.Group("/api")
// All endpoints require authentication except when someone wants to
// login (POST /authenticate)
user.VisitorAuthenticate(api.Group("/authenticate"))
api.Use(user.Authentication(true))
RegisterSimulationEndpoints(api.Group("/simulations"))
credjson, err := json.Marshal(cred)
msgOKjson, err := json.Marshal(msgOK)
if err != nil {
panic(err)
}
msgUsersjson, err := json.Marshal(msgUsers)
if err != nil {
panic(err)
}
msgUserAjson, err := json.Marshal(msgUserA)
if err != nil {
panic(err)
}
msgSimulationsjson, err := json.Marshal(msgSimulations)
if err != nil {
panic(err)
}
msgSimulationjson, err := json.Marshal(msgSimulation)
if err != nil {
panic(err)
}
simulationCjson, err := json.Marshal(simulationC)
if err != nil {
panic(err)
}
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
// test GET simulations/
common.TestEndpoint(t, router, token, "/api/simulations", "GET", nil, 200, string(msgSimulationsjson))
// test POST simulations/
common.TestEndpoint(t, router, token, "/api/simulations", "POST", simulationCjson, 200, string(msgOKjson))
// test GET simulations/:SimulationID
common.TestEndpoint(t, router, token, "/api/simulations/3", "GET", nil, 200, string(msgSimulationjson))
// test DELETE simulations/:SimulationID
common.TestEndpoint(t, router, token, "/api/simulations/3", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/simulations", "GET", nil, 200, string(msgSimulationsjson))
// test GET simulations/:SimulationID/users
common.TestEndpoint(t, router, token, "/api/simulations/1/users", "GET", nil, 200, string(msgUsersjson))
// test DELETE simulations/:SimulationID/user
common.TestEndpoint(t, router, token, "/api/simulations/1/user?username=User_B", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/simulations/1/users", "GET", nil, 200, string(msgUserAjson))
// test PUT simulations/:SimulationID/user
common.TestEndpoint(t, router, token, "/api/simulations/1/user?username=User_B", "PUT", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/simulations/1/users", "GET", nil, 200, string(msgUsersjson))
// test DELETE simulations/:SimulationID/user for logged in user User_A
common.TestEndpoint(t, router, token, "/api/simulations/1/user?username=User_A", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/simulations/1/users", "GET", nil, 422, "\"Access denied (for simulation ID).\"")
// TODO add tests for other return codes
}

View file

@ -6,7 +6,7 @@ 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/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
) )
func RegisterSimulationModelEndpoints(r *gin.RouterGroup) { func RegisterSimulationModelEndpoints(r *gin.RouterGroup) {
@ -18,27 +18,27 @@ func RegisterSimulationModelEndpoints(r *gin.RouterGroup) {
} }
// getSimulationModels godoc // getSimulationModels godoc
// @Summary Get all simulation models of simulation // @Summary Get all simulation models of scenario
// @ID getSimulationModels // @ID getSimulationModels
// @Produce json // @Produce json
// @Tags models // @Tags models
// @Success 200 {array} common.SimulationModelResponse "Array of models to which belong to simulation" // @Success 200 {array} common.SimulationModelResponse "Array of models to which belong to scenario"
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
// @Failure 404 "Not found" // @Failure 404 "Not found"
// @Failure 500 "Internal server error" // @Failure 500 "Internal server error"
// @Param simulationID query int true "Simulation ID" // @Param scenarioID query int true "Scenario ID"
// @Router /models [get] // @Router /models [get]
func getSimulationModels(c *gin.Context) { func getSimulationModels(c *gin.Context) {
ok, sim := simulation.CheckPermissions(c, common.Read, "query", -1) ok, so := scenario.CheckPermissions(c, common.Read, "query", -1)
if !ok { if !ok {
return return
} }
db := common.GetDB() db := common.GetDB()
var models []common.SimulationModel var models []common.SimulationModel
err := db.Order("ID asc").Model(sim).Related(&models, "Models").Error err := db.Order("ID asc").Model(so).Related(&models, "Models").Error
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
@ -50,12 +50,12 @@ func getSimulationModels(c *gin.Context) {
} }
// addSimulationModel godoc // addSimulationModel godoc
// @Summary Add a simulation model to a simulation // @Summary Add a simulation model to a scenario
// @ID addSimulationModel // @ID addSimulationModel
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Tags models // @Tags models
// @Param inputSimulationModel body common.SimulationModelResponse true "Simulation model to be added incl. IDs of simulation and simulator" // @Param inputSimulationModel body common.SimulationModelResponse true "Simulation model to be added incl. IDs of scenario and simulator"
// @Success 200 "OK." // @Success 200 "OK."
// @Failure 401 "Unauthorized Access" // @Failure 401 "Unauthorized Access"
// @Failure 403 "Access forbidden." // @Failure 403 "Access forbidden."
@ -74,12 +74,12 @@ func addSimulationModel(c *gin.Context) {
return return
} }
ok, _ := simulation.CheckPermissions(c, common.Create, "body", int(newModel.SimulationID)) ok, _ := scenario.CheckPermissions(c, common.Create, "body", int(newModel.ScenarioID))
if !ok { if !ok {
return return
} }
err = newModel.addToSimulation() err = newModel.addToScenario()
if common.ProvideErrorResponse(c, err) == false { if common.ProvideErrorResponse(c, err) == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "OK.", "message": "OK.",

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"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/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator"
) )
@ -27,10 +27,10 @@ func (m *SimulationModel) ByID(id uint) error {
return nil return nil
} }
func (m *SimulationModel) addToSimulation() error { func (m *SimulationModel) addToScenario() error {
db := common.GetDB() db := common.GetDB()
var sim simulation.Simulation var so scenario.Scenario
err := sim.ByID(m.SimulationID) err := so.ByID(m.ScenarioID)
if err != nil { if err != nil {
return err return err
} }
@ -49,8 +49,8 @@ func (m *SimulationModel) addToSimulation() error {
return err return err
} }
// associate simulation model with simulation // associate simulation model with scenario
err = db.Model(&sim).Association("SimulationModels").Append(m).Error err = db.Model(&so).Association("SimulationModels").Append(m).Error
return err return err
} }
@ -96,15 +96,15 @@ func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error
func (m *SimulationModel) delete() error { func (m *SimulationModel) delete() error {
db := common.GetDB() db := common.GetDB()
var sim simulation.Simulation var so scenario.Scenario
err := sim.ByID(m.SimulationID) err := so.ByID(m.ScenarioID)
if err != nil { if err != nil {
return err return err
} }
// remove association between SimulationModel and Simulation // remove association between SimulationModel and Scenario
// SimulationModel itself is not deleted from DB, it remains as "dangling" // SimulationModel itself is not deleted from DB, it remains as "dangling"
err = db.Model(&sim).Association("SimulationModels").Delete(m).Error err = db.Model(&so).Association("SimulationModels").Delete(m).Error
return err return err
} }

View file

@ -8,7 +8,7 @@ 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/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
) )
func CheckPermissions(c *gin.Context, operation common.CRUD, modelIDSource string, modelIDBody int) (bool, SimulationModel) { func CheckPermissions(c *gin.Context, operation common.CRUD, modelIDSource string, modelIDBody int) (bool, SimulationModel) {
@ -49,7 +49,7 @@ func CheckPermissions(c *gin.Context, operation common.CRUD, modelIDSource strin
return false, m return false, m
} }
ok, _ := simulation.CheckPermissions(c, operation, "body", int(m.SimulationID)) ok, _ := scenario.CheckPermissions(c, operation, "body", int(m.ScenarioID))
if !ok { if !ok {
return false, m return false, m
} }

View file

@ -31,7 +31,7 @@ var modelA = common.SimulationModelResponse{
Name: "SimulationModel_A", Name: "SimulationModel_A",
OutputLength: 1, OutputLength: 1,
InputLength: 1, InputLength: 1,
SimulationID: 1, ScenarioID: 1,
SimulatorID: 1, SimulatorID: 1,
StartParams: "", StartParams: "",
} }
@ -41,7 +41,7 @@ var modelB = common.SimulationModelResponse{
Name: "SimulationModel_B", Name: "SimulationModel_B",
OutputLength: 1, OutputLength: 1,
InputLength: 1, InputLength: 1,
SimulationID: 1, ScenarioID: 1,
SimulatorID: 1, SimulatorID: 1,
StartParams: "", StartParams: "",
} }
@ -51,7 +51,7 @@ var modelC = common.SimulationModel{
Name: "SimulationModel_C", Name: "SimulationModel_C",
OutputLength: 1, OutputLength: 1,
InputLength: 1, InputLength: 1,
SimulationID: 1, ScenarioID: 1,
SimulatorID: 1, SimulatorID: 1,
StartParameters: "test", StartParameters: "test",
InputMapping: nil, InputMapping: nil,
@ -63,7 +63,7 @@ var modelCupdated = common.SimulationModel{
Name: "SimulationModel_CUpdated", Name: "SimulationModel_CUpdated",
OutputLength: modelC.OutputLength, OutputLength: modelC.OutputLength,
InputLength: modelC.InputLength, InputLength: modelC.InputLength,
SimulationID: modelC.SimulationID, ScenarioID: modelC.ScenarioID,
SimulatorID: 2, SimulatorID: 2,
StartParameters: modelC.StartParameters, StartParameters: modelC.StartParameters,
InputMapping: modelC.InputMapping, InputMapping: modelC.InputMapping,
@ -75,7 +75,7 @@ var modelC_response = common.SimulationModelResponse{
Name: modelC.Name, Name: modelC.Name,
InputLength: modelC.InputLength, InputLength: modelC.InputLength,
OutputLength: modelC.OutputLength, OutputLength: modelC.OutputLength,
SimulationID: modelC.SimulationID, ScenarioID: modelC.ScenarioID,
SimulatorID: modelC.SimulatorID, SimulatorID: modelC.SimulatorID,
StartParams: modelC.StartParameters, StartParams: modelC.StartParameters,
} }
@ -85,7 +85,7 @@ var modelC_responseUpdated = common.SimulationModelResponse{
Name: modelCupdated.Name, Name: modelCupdated.Name,
InputLength: modelC.InputLength, InputLength: modelC.InputLength,
OutputLength: modelC.OutputLength, OutputLength: modelC.OutputLength,
SimulationID: modelC.SimulationID, ScenarioID: modelC.ScenarioID,
SimulatorID: modelCupdated.SimulatorID, SimulatorID: modelCupdated.SimulatorID,
StartParams: modelC.StartParameters, StartParams: modelC.StartParameters,
} }
@ -163,7 +163,7 @@ func TestSimulationModelEndpoints(t *testing.T) {
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200) token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
// test GET models // test GET models
common.TestEndpoint(t, router, token, "/api/models?simulationID=1", "GET", nil, 200, string(msgModelsjson)) common.TestEndpoint(t, router, token, "/api/models?scenarioID=1", "GET", nil, 200, string(msgModelsjson))
// test POST models // test POST models
common.TestEndpoint(t, router, token, "/api/models", "POST", modelCjson, 200, string(msgOKjson)) common.TestEndpoint(t, router, token, "/api/models", "POST", modelCjson, 200, string(msgOKjson))
@ -177,7 +177,7 @@ func TestSimulationModelEndpoints(t *testing.T) {
// test DELETE models/:ModelID // test DELETE models/:ModelID
common.TestEndpoint(t, router, token, "/api/models/3", "DELETE", nil, 200, string(msgOKjson)) common.TestEndpoint(t, router, token, "/api/models/3", "DELETE", nil, 200, string(msgOKjson))
common.TestEndpoint(t, router, token, "/api/models?simulationID=1", "GET", nil, 200, string(msgModelsjson)) common.TestEndpoint(t, router, token, "/api/models?scenarioID=1", "GET", nil, 200, string(msgModelsjson))
// TODO add testing for other return codes // TODO add testing for other return codes

View file

@ -2,8 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/signal"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -13,7 +11,9 @@ 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/doc/api" // doc/api folder is used by Swag CLI, you have to import it _ "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/dashboard" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/dashboard"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/scenario"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/signal"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulationmodel" "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/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"
@ -54,7 +54,7 @@ func main() {
api.Use(user.Authentication(true)) api.Use(user.Authentication(true))
simulation.RegisterSimulationEndpoints(api.Group("/simulations")) scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
simulationmodel.RegisterSimulationModelEndpoints(api.Group("/models")) simulationmodel.RegisterSimulationModelEndpoints(api.Group("/models"))
signal.RegisterSignalEndpoints(api.Group("/signals")) signal.RegisterSignalEndpoints(api.Group("/signals"))
dashboard.RegisterDashboardEndpoints(api.Group("/dashboards")) dashboard.RegisterDashboardEndpoints(api.Group("/dashboards"))