mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
simulationModel: rename response field from model(s) to simulationModel(s)
This commit is contained in:
parent
33d50a148d
commit
13f2ae7de3
10 changed files with 74 additions and 74 deletions
|
@ -1,6 +1,6 @@
|
|||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2019-11-14 12:30:44.260846213 +0100 CET m=+0.099575699
|
||||
// 2019-11-26 14:19:55.359561459 +0100 CET m=+0.107753669
|
||||
|
||||
package docs
|
||||
|
||||
|
@ -820,7 +820,7 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Get all simulation models of scenario",
|
||||
"operationId": "getSimulationModels",
|
||||
|
@ -879,7 +879,7 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Add a simulation model to a scenario",
|
||||
"operationId": "addSimulationModel",
|
||||
|
@ -947,7 +947,7 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Get a simulation model",
|
||||
"operationId": "getSimulationModel",
|
||||
|
@ -1013,7 +1013,7 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Update a simulation model",
|
||||
"operationId": "updateSimulationModel",
|
||||
|
@ -1086,7 +1086,7 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Delete a simulation model",
|
||||
"operationId": "deleteSimulationModel",
|
||||
|
@ -3500,7 +3500,7 @@ var doc = `{
|
|||
"docs.ResponseSimulationModel": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"simulationModel": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/database.SimulationModel"
|
||||
}
|
||||
|
@ -3509,7 +3509,7 @@ var doc = `{
|
|||
"docs.ResponseSimulationModels": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"models": {
|
||||
"simulationModels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/database.SimulationModel"
|
||||
|
@ -3688,7 +3688,7 @@ var doc = `{
|
|||
"simulationmodel.addSimulationModelRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"simulationModel": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/simulationmodel.validNewSimulationModel"
|
||||
}
|
||||
|
@ -3697,7 +3697,7 @@ var doc = `{
|
|||
"simulationmodel.updateSimulationModelRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"simulationModel": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel"
|
||||
}
|
||||
|
|
|
@ -63,11 +63,11 @@ type ResponseScenario struct {
|
|||
}
|
||||
|
||||
type ResponseSimulationModels struct {
|
||||
models []database.SimulationModel
|
||||
simulationModels []database.SimulationModel
|
||||
}
|
||||
|
||||
type ResponseSimulationModel struct {
|
||||
model database.SimulationModel
|
||||
simulationModel database.SimulationModel
|
||||
}
|
||||
|
||||
type ResponseDashboards struct {
|
||||
|
|
|
@ -805,7 +805,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Get all simulation models of scenario",
|
||||
"operationId": "getSimulationModels",
|
||||
|
@ -864,7 +864,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Add a simulation model to a scenario",
|
||||
"operationId": "addSimulationModel",
|
||||
|
@ -932,7 +932,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Get a simulation model",
|
||||
"operationId": "getSimulationModel",
|
||||
|
@ -998,7 +998,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Update a simulation model",
|
||||
"operationId": "updateSimulationModel",
|
||||
|
@ -1071,7 +1071,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"models"
|
||||
"simulationModels"
|
||||
],
|
||||
"summary": "Delete a simulation model",
|
||||
"operationId": "deleteSimulationModel",
|
||||
|
@ -3485,7 +3485,7 @@
|
|||
"docs.ResponseSimulationModel": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"simulationModel": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/database.SimulationModel"
|
||||
}
|
||||
|
@ -3494,7 +3494,7 @@
|
|||
"docs.ResponseSimulationModels": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"models": {
|
||||
"simulationModels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/database.SimulationModel"
|
||||
|
@ -3673,7 +3673,7 @@
|
|||
"simulationmodel.addSimulationModelRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"simulationModel": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/simulationmodel.validNewSimulationModel"
|
||||
}
|
||||
|
@ -3682,7 +3682,7 @@
|
|||
"simulationmodel.updateSimulationModelRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"simulationModel": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel"
|
||||
}
|
||||
|
|
|
@ -293,13 +293,13 @@ definitions:
|
|||
type: object
|
||||
docs.ResponseSimulationModel:
|
||||
properties:
|
||||
model:
|
||||
simulationModel:
|
||||
$ref: '#/definitions/database.SimulationModel'
|
||||
type: object
|
||||
type: object
|
||||
docs.ResponseSimulationModels:
|
||||
properties:
|
||||
models:
|
||||
simulationModels:
|
||||
items:
|
||||
$ref: '#/definitions/database.SimulationModel'
|
||||
type: array
|
||||
|
@ -417,13 +417,13 @@ definitions:
|
|||
type: object
|
||||
simulationmodel.addSimulationModelRequest:
|
||||
properties:
|
||||
model:
|
||||
simulationModel:
|
||||
$ref: '#/definitions/simulationmodel.validNewSimulationModel'
|
||||
type: object
|
||||
type: object
|
||||
simulationmodel.updateSimulationModelRequest:
|
||||
properties:
|
||||
model:
|
||||
simulationModel:
|
||||
$ref: '#/definitions/simulationmodel.validUpdatedSimulationModel'
|
||||
type: object
|
||||
type: object
|
||||
|
@ -1221,7 +1221,7 @@ paths:
|
|||
type: object
|
||||
summary: Get all simulation models of scenario
|
||||
tags:
|
||||
- models
|
||||
- simulationModels
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -1269,7 +1269,7 @@ paths:
|
|||
type: object
|
||||
summary: Add a simulation model to a scenario
|
||||
tags:
|
||||
- models
|
||||
- simulationModels
|
||||
/models/{modelID}:
|
||||
delete:
|
||||
operationId: deleteSimulationModel
|
||||
|
@ -1314,7 +1314,7 @@ paths:
|
|||
type: object
|
||||
summary: Delete a simulation model
|
||||
tags:
|
||||
- models
|
||||
- simulationModels
|
||||
get:
|
||||
operationId: getSimulationModel
|
||||
parameters:
|
||||
|
@ -1358,7 +1358,7 @@ paths:
|
|||
type: object
|
||||
summary: Get a simulation model
|
||||
tags:
|
||||
- models
|
||||
- simulationModels
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -1411,7 +1411,7 @@ paths:
|
|||
type: object
|
||||
summary: Update a simulation model
|
||||
tags:
|
||||
- models
|
||||
- simulationModels
|
||||
/scenarios:
|
||||
get:
|
||||
operationId: getScenarios
|
||||
|
|
|
@ -135,7 +135,7 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI
|
|||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
}
|
||||
_, resp, _ = helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
|
||||
// Read newSimulationModel's ID from the response
|
||||
newSimulationModelID, _ := helper.GetResponseID(resp)
|
||||
|
|
|
@ -114,7 +114,7 @@ func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID u
|
|||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
}
|
||||
_, resp, _ = helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
|
||||
// Read newSimulationModel's ID from the response
|
||||
newSimulationModelID, _ := helper.GetResponseID(resp)
|
||||
|
@ -235,7 +235,7 @@ func TestAddSignal(t *testing.T) {
|
|||
}
|
||||
// this should NOT work and return a unprocessable entity 442 status code
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/signals", "POST", helper.KeyModels{"model": malformedNewSignal})
|
||||
"/api/signals", "POST", helper.KeyModels{"signal": malformedNewSignal})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func RegisterSimulationModelEndpoints(r *gin.RouterGroup) {
|
|||
// @Summary Get all simulation models of scenario
|
||||
// @ID getSimulationModels
|
||||
// @Produce json
|
||||
// @Tags models
|
||||
// @Tags simulationModels
|
||||
// @Success 200 {object} docs.ResponseSimulationModels "Simulation models which belong to scenario"
|
||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||
|
@ -62,7 +62,7 @@ func getSimulationModels(c *gin.Context) {
|
|||
var models []database.SimulationModel
|
||||
err := db.Order("ID asc").Model(so).Related(&models, "Models").Error
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"models": models})
|
||||
c.JSON(http.StatusOK, gin.H{"simulationModels": models})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func getSimulationModels(c *gin.Context) {
|
|||
// @ID addSimulationModel
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags models
|
||||
// @Tags simulationModels
|
||||
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added"
|
||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||
|
@ -109,7 +109,7 @@ func addSimulationModel(c *gin.Context) {
|
|||
// add the new simulation model to the scenario
|
||||
err = newSimulationModel.addToScenario()
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"model": newSimulationModel.SimulationModel})
|
||||
c.JSON(http.StatusOK, gin.H{"simulationModel": newSimulationModel.SimulationModel})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func addSimulationModel(c *gin.Context) {
|
|||
// updateSimulationModel godoc
|
||||
// @Summary Update a simulation model
|
||||
// @ID updateSimulationModel
|
||||
// @Tags models
|
||||
// @Tags simulationModels
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added"
|
||||
|
@ -144,7 +144,7 @@ func updateSimulationModel(c *gin.Context) {
|
|||
}
|
||||
|
||||
// Validate the request
|
||||
if err := req.Model.validate(); err != nil {
|
||||
if err := req.SimulationModel.validate(); err != nil {
|
||||
helper.BadRequestError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func updateSimulationModel(c *gin.Context) {
|
|||
// Finally, update the simulation model
|
||||
err = oldSimulationModel.Update(updatedSimulationModel)
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"model": updatedSimulationModel.SimulationModel})
|
||||
c.JSON(http.StatusOK, gin.H{"simulationModel": updatedSimulationModel.SimulationModel})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ func updateSimulationModel(c *gin.Context) {
|
|||
// getSimulationModel godoc
|
||||
// @Summary Get a simulation model
|
||||
// @ID getSimulationModel
|
||||
// @Tags models
|
||||
// @Tags simulationModels
|
||||
// @Produce json
|
||||
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was requested"
|
||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||
|
@ -180,13 +180,13 @@ func getSimulationModel(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"model": m.SimulationModel})
|
||||
c.JSON(http.StatusOK, gin.H{"simulationModel": m.SimulationModel})
|
||||
}
|
||||
|
||||
// deleteSimulationModel godoc
|
||||
// @Summary Delete a simulation model
|
||||
// @ID deleteSimulationModel
|
||||
// @Tags models
|
||||
// @Tags simulationModels
|
||||
// @Produce json
|
||||
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was deleted"
|
||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||
|
@ -205,6 +205,6 @@ func deleteSimulationModel(c *gin.Context) {
|
|||
|
||||
err := m.delete()
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"model": m.SimulationModel})
|
||||
c.JSON(http.StatusOK, gin.H{"simulationModel": m.SimulationModel})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ func TestAddSimulationModel(t *testing.T) {
|
|||
// try to POST with no access
|
||||
// should result in unprocessable entity
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
@ -190,12 +190,12 @@ func TestAddSimulationModel(t *testing.T) {
|
|||
|
||||
// test POST models/ $newSimulationModel
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Compare POST's response with the newSimulationModel
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"model": newSimulationModel})
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Read newSimulationModel's ID from the response
|
||||
|
@ -209,7 +209,7 @@ func TestAddSimulationModel(t *testing.T) {
|
|||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Compare GET's response with the newSimulationModel
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"model": newSimulationModel})
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// try to POST a malformed simulation model
|
||||
|
@ -219,7 +219,7 @@ func TestAddSimulationModel(t *testing.T) {
|
|||
}
|
||||
// this should NOT work and return a unprocessable entity 442 status code
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": malformedNewSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": malformedNewSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
@ -261,7 +261,7 @@ func TestUpdateSimulationModel(t *testing.T) {
|
|||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
@ -282,7 +282,7 @@ func TestUpdateSimulationModel(t *testing.T) {
|
|||
// try to PUT with no access
|
||||
// should result in unprocessable entity
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"model": updatedSimulationModel})
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
@ -294,7 +294,7 @@ func TestUpdateSimulationModel(t *testing.T) {
|
|||
// try to PUT as guest
|
||||
// should NOT work and result in unprocessable entity
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"model": updatedSimulationModel})
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
@ -312,24 +312,24 @@ func TestUpdateSimulationModel(t *testing.T) {
|
|||
|
||||
// test PUT
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"model": updatedSimulationModel})
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Compare PUT's response with the updatedSimulationModel
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"model": updatedSimulationModel})
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
|
||||
//Change simulator ID to use second simulator available in DB
|
||||
updatedSimulationModel.SimulatorID = simulatorID + 1
|
||||
// test PUT again
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"model": updatedSimulationModel})
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Compare PUT's response with the updatedSimulationModel
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"model": updatedSimulationModel})
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Get the updatedSimulationModel
|
||||
|
@ -339,12 +339,12 @@ func TestUpdateSimulationModel(t *testing.T) {
|
|||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Compare GET's response with the updatedSimulationModel
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"model": updatedSimulationModel})
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// try to update a simulation model that does not exist (should return not found 404 status code)
|
||||
code, resp, err = helper.TestEndpoint(router, token,
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID+1), "PUT", helper.KeyModels{"model": updatedSimulationModel})
|
||||
fmt.Sprintf("/api/models/%v", newSimulationModelID+1), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 404, code, "Response body: \n%v\n", resp)
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ func TestDeleteSimulationModel(t *testing.T) {
|
|||
|
||||
// test POST models/ $newSimulationModel
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
@ -410,7 +410,7 @@ func TestDeleteSimulationModel(t *testing.T) {
|
|||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// Compare DELETE's response with the newSimulationModel
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"model": newSimulationModel})
|
||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Again count the number of all the simulation models returned
|
||||
|
@ -444,7 +444,7 @@ func TestGetAllSimulationModelsOfScenario(t *testing.T) {
|
|||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"model": newSimulationModel})
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
assert.NoError(t, err)
|
||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||
|
||||
|
|
|
@ -44,11 +44,11 @@ type validUpdatedSimulationModel struct {
|
|||
}
|
||||
|
||||
type addSimulationModelRequest struct {
|
||||
Model validNewSimulationModel `json:"model"`
|
||||
SimulationModel validNewSimulationModel `json:"simulationModel"`
|
||||
}
|
||||
|
||||
type updateSimulationModelRequest struct {
|
||||
Model validUpdatedSimulationModel `json:"model"`
|
||||
SimulationModel validUpdatedSimulationModel `json:"simulationModel"`
|
||||
}
|
||||
|
||||
func (r *addSimulationModelRequest) validate() error {
|
||||
|
@ -66,10 +66,10 @@ func (r *validUpdatedSimulationModel) validate() error {
|
|||
func (r *addSimulationModelRequest) createSimulationModel() SimulationModel {
|
||||
var s SimulationModel
|
||||
|
||||
s.Name = r.Model.Name
|
||||
s.ScenarioID = r.Model.ScenarioID
|
||||
s.SimulatorID = r.Model.SimulatorID
|
||||
s.StartParameters = r.Model.StartParameters
|
||||
s.Name = r.SimulationModel.Name
|
||||
s.ScenarioID = r.SimulationModel.ScenarioID
|
||||
s.SimulatorID = r.SimulationModel.SimulatorID
|
||||
s.StartParameters = r.SimulationModel.StartParameters
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -78,23 +78,23 @@ func (r *updateSimulationModelRequest) updatedSimulationModel(oldSimulationModel
|
|||
// Use the old SimulationModel as a basis for the updated Simulation model
|
||||
s := oldSimulationModel
|
||||
|
||||
if r.Model.Name != "" {
|
||||
s.Name = r.Model.Name
|
||||
if r.SimulationModel.Name != "" {
|
||||
s.Name = r.SimulationModel.Name
|
||||
}
|
||||
|
||||
if r.Model.SimulatorID != 0 {
|
||||
s.SimulatorID = r.Model.SimulatorID
|
||||
if r.SimulationModel.SimulatorID != 0 {
|
||||
s.SimulatorID = r.SimulationModel.SimulatorID
|
||||
}
|
||||
|
||||
// only update Params if not empty
|
||||
var emptyJson postgres.Jsonb
|
||||
// Serialize empty json and params
|
||||
emptyJson_ser, _ := json.Marshal(emptyJson)
|
||||
startParams_ser, _ := json.Marshal(r.Model.StartParameters)
|
||||
startParams_ser, _ := json.Marshal(r.SimulationModel.StartParameters)
|
||||
opts := jsondiff.DefaultConsoleOptions()
|
||||
diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts)
|
||||
if diff.String() != "FullMatch" {
|
||||
s.StartParameters = r.Model.StartParameters
|
||||
s.StartParameters = r.SimulationModel.StartParameters
|
||||
}
|
||||
|
||||
return s
|
||||
|
|
|
@ -227,7 +227,7 @@ func getModelsOfSimulator(c *gin.Context) {
|
|||
// get all associated simulation models
|
||||
allModels, _, err := s.getModels()
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"models": allModels})
|
||||
c.JSON(http.StatusOK, gin.H{"simulationModels": allModels})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue