simulationModel: rename response field from model(s) to simulationModel(s)

This commit is contained in:
Sonja Happ 2019-11-26 14:22:26 +01:00
parent 33d50a148d
commit 13f2ae7de3
10 changed files with 74 additions and 74 deletions

View file

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // 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 package docs
@ -820,7 +820,7 @@ var doc = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Get all simulation models of scenario", "summary": "Get all simulation models of scenario",
"operationId": "getSimulationModels", "operationId": "getSimulationModels",
@ -879,7 +879,7 @@ var doc = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Add a simulation model to a scenario", "summary": "Add a simulation model to a scenario",
"operationId": "addSimulationModel", "operationId": "addSimulationModel",
@ -947,7 +947,7 @@ var doc = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Get a simulation model", "summary": "Get a simulation model",
"operationId": "getSimulationModel", "operationId": "getSimulationModel",
@ -1013,7 +1013,7 @@ var doc = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Update a simulation model", "summary": "Update a simulation model",
"operationId": "updateSimulationModel", "operationId": "updateSimulationModel",
@ -1086,7 +1086,7 @@ var doc = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Delete a simulation model", "summary": "Delete a simulation model",
"operationId": "deleteSimulationModel", "operationId": "deleteSimulationModel",
@ -3500,7 +3500,7 @@ var doc = `{
"docs.ResponseSimulationModel": { "docs.ResponseSimulationModel": {
"type": "object", "type": "object",
"properties": { "properties": {
"model": { "simulationModel": {
"type": "object", "type": "object",
"$ref": "#/definitions/database.SimulationModel" "$ref": "#/definitions/database.SimulationModel"
} }
@ -3509,7 +3509,7 @@ var doc = `{
"docs.ResponseSimulationModels": { "docs.ResponseSimulationModels": {
"type": "object", "type": "object",
"properties": { "properties": {
"models": { "simulationModels": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/database.SimulationModel" "$ref": "#/definitions/database.SimulationModel"
@ -3688,7 +3688,7 @@ var doc = `{
"simulationmodel.addSimulationModelRequest": { "simulationmodel.addSimulationModelRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"model": { "simulationModel": {
"type": "object", "type": "object",
"$ref": "#/definitions/simulationmodel.validNewSimulationModel" "$ref": "#/definitions/simulationmodel.validNewSimulationModel"
} }
@ -3697,7 +3697,7 @@ var doc = `{
"simulationmodel.updateSimulationModelRequest": { "simulationmodel.updateSimulationModelRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"model": { "simulationModel": {
"type": "object", "type": "object",
"$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel" "$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel"
} }

View file

@ -63,11 +63,11 @@ type ResponseScenario struct {
} }
type ResponseSimulationModels struct { type ResponseSimulationModels struct {
models []database.SimulationModel simulationModels []database.SimulationModel
} }
type ResponseSimulationModel struct { type ResponseSimulationModel struct {
model database.SimulationModel simulationModel database.SimulationModel
} }
type ResponseDashboards struct { type ResponseDashboards struct {

View file

@ -805,7 +805,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Get all simulation models of scenario", "summary": "Get all simulation models of scenario",
"operationId": "getSimulationModels", "operationId": "getSimulationModels",
@ -864,7 +864,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Add a simulation model to a scenario", "summary": "Add a simulation model to a scenario",
"operationId": "addSimulationModel", "operationId": "addSimulationModel",
@ -932,7 +932,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Get a simulation model", "summary": "Get a simulation model",
"operationId": "getSimulationModel", "operationId": "getSimulationModel",
@ -998,7 +998,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Update a simulation model", "summary": "Update a simulation model",
"operationId": "updateSimulationModel", "operationId": "updateSimulationModel",
@ -1071,7 +1071,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"models" "simulationModels"
], ],
"summary": "Delete a simulation model", "summary": "Delete a simulation model",
"operationId": "deleteSimulationModel", "operationId": "deleteSimulationModel",
@ -3485,7 +3485,7 @@
"docs.ResponseSimulationModel": { "docs.ResponseSimulationModel": {
"type": "object", "type": "object",
"properties": { "properties": {
"model": { "simulationModel": {
"type": "object", "type": "object",
"$ref": "#/definitions/database.SimulationModel" "$ref": "#/definitions/database.SimulationModel"
} }
@ -3494,7 +3494,7 @@
"docs.ResponseSimulationModels": { "docs.ResponseSimulationModels": {
"type": "object", "type": "object",
"properties": { "properties": {
"models": { "simulationModels": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/database.SimulationModel" "$ref": "#/definitions/database.SimulationModel"
@ -3673,7 +3673,7 @@
"simulationmodel.addSimulationModelRequest": { "simulationmodel.addSimulationModelRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"model": { "simulationModel": {
"type": "object", "type": "object",
"$ref": "#/definitions/simulationmodel.validNewSimulationModel" "$ref": "#/definitions/simulationmodel.validNewSimulationModel"
} }
@ -3682,7 +3682,7 @@
"simulationmodel.updateSimulationModelRequest": { "simulationmodel.updateSimulationModelRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"model": { "simulationModel": {
"type": "object", "type": "object",
"$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel" "$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel"
} }

View file

@ -293,13 +293,13 @@ definitions:
type: object type: object
docs.ResponseSimulationModel: docs.ResponseSimulationModel:
properties: properties:
model: simulationModel:
$ref: '#/definitions/database.SimulationModel' $ref: '#/definitions/database.SimulationModel'
type: object type: object
type: object type: object
docs.ResponseSimulationModels: docs.ResponseSimulationModels:
properties: properties:
models: simulationModels:
items: items:
$ref: '#/definitions/database.SimulationModel' $ref: '#/definitions/database.SimulationModel'
type: array type: array
@ -417,13 +417,13 @@ definitions:
type: object type: object
simulationmodel.addSimulationModelRequest: simulationmodel.addSimulationModelRequest:
properties: properties:
model: simulationModel:
$ref: '#/definitions/simulationmodel.validNewSimulationModel' $ref: '#/definitions/simulationmodel.validNewSimulationModel'
type: object type: object
type: object type: object
simulationmodel.updateSimulationModelRequest: simulationmodel.updateSimulationModelRequest:
properties: properties:
model: simulationModel:
$ref: '#/definitions/simulationmodel.validUpdatedSimulationModel' $ref: '#/definitions/simulationmodel.validUpdatedSimulationModel'
type: object type: object
type: object type: object
@ -1221,7 +1221,7 @@ paths:
type: object type: object
summary: Get all simulation models of scenario summary: Get all simulation models of scenario
tags: tags:
- models - simulationModels
post: post:
consumes: consumes:
- application/json - application/json
@ -1269,7 +1269,7 @@ paths:
type: object type: object
summary: Add a simulation model to a scenario summary: Add a simulation model to a scenario
tags: tags:
- models - simulationModels
/models/{modelID}: /models/{modelID}:
delete: delete:
operationId: deleteSimulationModel operationId: deleteSimulationModel
@ -1314,7 +1314,7 @@ paths:
type: object type: object
summary: Delete a simulation model summary: Delete a simulation model
tags: tags:
- models - simulationModels
get: get:
operationId: getSimulationModel operationId: getSimulationModel
parameters: parameters:
@ -1358,7 +1358,7 @@ paths:
type: object type: object
summary: Get a simulation model summary: Get a simulation model
tags: tags:
- models - simulationModels
put: put:
consumes: consumes:
- application/json - application/json
@ -1411,7 +1411,7 @@ paths:
type: object type: object
summary: Update a simulation model summary: Update a simulation model
tags: tags:
- models - simulationModels
/scenarios: /scenarios:
get: get:
operationId: getScenarios operationId: getScenarios

View file

@ -135,7 +135,7 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI
StartParameters: database.SimulationModelA.StartParameters, StartParameters: database.SimulationModelA.StartParameters,
} }
_, resp, _ = helper.TestEndpoint(router, token, _, 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 // Read newSimulationModel's ID from the response
newSimulationModelID, _ := helper.GetResponseID(resp) newSimulationModelID, _ := helper.GetResponseID(resp)

View file

@ -114,7 +114,7 @@ func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID u
StartParameters: database.SimulationModelA.StartParameters, StartParameters: database.SimulationModelA.StartParameters,
} }
_, resp, _ = helper.TestEndpoint(router, token, _, 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 // Read newSimulationModel's ID from the response
newSimulationModelID, _ := helper.GetResponseID(resp) 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 // this should NOT work and return a unprocessable entity 442 status code
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)

View file

@ -43,7 +43,7 @@ func RegisterSimulationModelEndpoints(r *gin.RouterGroup) {
// @Summary Get all simulation models of scenario // @Summary Get all simulation models of scenario
// @ID getSimulationModels // @ID getSimulationModels
// @Produce json // @Produce json
// @Tags models // @Tags simulationModels
// @Success 200 {object} docs.ResponseSimulationModels "Simulation models which belong to scenario" // @Success 200 {object} docs.ResponseSimulationModels "Simulation models which belong to scenario"
// @Failure 404 {object} docs.ResponseError "Not found" // @Failure 404 {object} docs.ResponseError "Not found"
// @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 422 {object} docs.ResponseError "Unprocessable entity"
@ -62,7 +62,7 @@ func getSimulationModels(c *gin.Context) {
var models []database.SimulationModel var models []database.SimulationModel
err := db.Order("ID asc").Model(so).Related(&models, "Models").Error err := db.Order("ID asc").Model(so).Related(&models, "Models").Error
if !helper.DBError(c, err) { 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 // @ID addSimulationModel
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Tags models // @Tags simulationModels
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added" // @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added"
// @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 400 {object} docs.ResponseError "Bad request"
// @Failure 404 {object} docs.ResponseError "Not found" // @Failure 404 {object} docs.ResponseError "Not found"
@ -109,7 +109,7 @@ func addSimulationModel(c *gin.Context) {
// add the new simulation model to the scenario // add the new simulation model to the scenario
err = newSimulationModel.addToScenario() err = newSimulationModel.addToScenario()
if !helper.DBError(c, err) { 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 // updateSimulationModel godoc
// @Summary Update a simulation model // @Summary Update a simulation model
// @ID updateSimulationModel // @ID updateSimulationModel
// @Tags models // @Tags simulationModels
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added" // @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added"
@ -144,7 +144,7 @@ func updateSimulationModel(c *gin.Context) {
} }
// Validate the request // Validate the request
if err := req.Model.validate(); err != nil { if err := req.SimulationModel.validate(); err != nil {
helper.BadRequestError(c, err.Error()) helper.BadRequestError(c, err.Error())
return return
} }
@ -155,7 +155,7 @@ func updateSimulationModel(c *gin.Context) {
// Finally, update the simulation model // Finally, update the simulation model
err = oldSimulationModel.Update(updatedSimulationModel) err = oldSimulationModel.Update(updatedSimulationModel)
if !helper.DBError(c, err) { 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 // getSimulationModel godoc
// @Summary Get a simulation model // @Summary Get a simulation model
// @ID getSimulationModel // @ID getSimulationModel
// @Tags models // @Tags simulationModels
// @Produce json // @Produce json
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was requested" // @Success 200 {object} docs.ResponseSimulationModel "simulation model that was requested"
// @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 400 {object} docs.ResponseError "Bad request"
@ -180,13 +180,13 @@ func getSimulationModel(c *gin.Context) {
return return
} }
c.JSON(http.StatusOK, gin.H{"model": m.SimulationModel}) c.JSON(http.StatusOK, gin.H{"simulationModel": m.SimulationModel})
} }
// deleteSimulationModel godoc // deleteSimulationModel godoc
// @Summary Delete a simulation model // @Summary Delete a simulation model
// @ID deleteSimulationModel // @ID deleteSimulationModel
// @Tags models // @Tags simulationModels
// @Produce json // @Produce json
// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was deleted" // @Success 200 {object} docs.ResponseSimulationModel "simulation model that was deleted"
// @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 400 {object} docs.ResponseError "Bad request"
@ -205,6 +205,6 @@ func deleteSimulationModel(c *gin.Context) {
err := m.delete() err := m.delete()
if !helper.DBError(c, err) { if !helper.DBError(c, err) {
c.JSON(http.StatusOK, gin.H{"model": m.SimulationModel}) c.JSON(http.StatusOK, gin.H{"simulationModel": m.SimulationModel})
} }
} }

View file

@ -168,7 +168,7 @@ func TestAddSimulationModel(t *testing.T) {
// try to POST with no access // try to POST with no access
// should result in unprocessable entity // should result in unprocessable entity
code, resp, err := helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
@ -190,12 +190,12 @@ func TestAddSimulationModel(t *testing.T) {
// test POST models/ $newSimulationModel // test POST models/ $newSimulationModel
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare POST's response with the newSimulationModel // 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) assert.NoError(t, err)
// Read newSimulationModel's ID from the response // 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) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare GET's response with the newSimulationModel // 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) assert.NoError(t, err)
// try to POST a malformed simulation model // 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 // this should NOT work and return a unprocessable entity 442 status code
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
@ -261,7 +261,7 @@ func TestUpdateSimulationModel(t *testing.T) {
StartParameters: database.SimulationModelA.StartParameters, StartParameters: database.SimulationModelA.StartParameters,
} }
code, resp, err := helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) 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 // try to PUT with no access
// should result in unprocessable entity // should result in unprocessable entity
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) 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 // try to PUT as guest
// should NOT work and result in unprocessable entity // should NOT work and result in unprocessable entity
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
@ -312,24 +312,24 @@ func TestUpdateSimulationModel(t *testing.T) {
// test PUT // test PUT
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare PUT's response with the updatedSimulationModel // 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) assert.NoError(t, err)
//Change simulator ID to use second simulator available in DB //Change simulator ID to use second simulator available in DB
updatedSimulationModel.SimulatorID = simulatorID + 1 updatedSimulationModel.SimulatorID = simulatorID + 1
// test PUT again // test PUT again
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare PUT's response with the updatedSimulationModel // 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) assert.NoError(t, err)
// Get the updatedSimulationModel // Get the updatedSimulationModel
@ -339,12 +339,12 @@ func TestUpdateSimulationModel(t *testing.T) {
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare GET's response with the updatedSimulationModel // 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) assert.NoError(t, err)
// try to update a simulation model that does not exist (should return not found 404 status code) // try to update a simulation model that does not exist (should return not found 404 status code)
code, resp, err = helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 404, code, "Response body: \n%v\n", resp) assert.Equalf(t, 404, code, "Response body: \n%v\n", resp)
} }
@ -373,7 +373,7 @@ func TestDeleteSimulationModel(t *testing.T) {
// test POST models/ $newSimulationModel // test POST models/ $newSimulationModel
code, resp, err := helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) 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) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare DELETE's response with the newSimulationModel // 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) assert.NoError(t, err)
// Again count the number of all the simulation models returned // Again count the number of all the simulation models returned
@ -444,7 +444,7 @@ func TestGetAllSimulationModelsOfScenario(t *testing.T) {
StartParameters: database.SimulationModelA.StartParameters, StartParameters: database.SimulationModelA.StartParameters,
} }
code, resp, err := helper.TestEndpoint(router, token, 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.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)

View file

@ -44,11 +44,11 @@ type validUpdatedSimulationModel struct {
} }
type addSimulationModelRequest struct { type addSimulationModelRequest struct {
Model validNewSimulationModel `json:"model"` SimulationModel validNewSimulationModel `json:"simulationModel"`
} }
type updateSimulationModelRequest struct { type updateSimulationModelRequest struct {
Model validUpdatedSimulationModel `json:"model"` SimulationModel validUpdatedSimulationModel `json:"simulationModel"`
} }
func (r *addSimulationModelRequest) validate() error { func (r *addSimulationModelRequest) validate() error {
@ -66,10 +66,10 @@ func (r *validUpdatedSimulationModel) validate() error {
func (r *addSimulationModelRequest) createSimulationModel() SimulationModel { func (r *addSimulationModelRequest) createSimulationModel() SimulationModel {
var s SimulationModel var s SimulationModel
s.Name = r.Model.Name s.Name = r.SimulationModel.Name
s.ScenarioID = r.Model.ScenarioID s.ScenarioID = r.SimulationModel.ScenarioID
s.SimulatorID = r.Model.SimulatorID s.SimulatorID = r.SimulationModel.SimulatorID
s.StartParameters = r.Model.StartParameters s.StartParameters = r.SimulationModel.StartParameters
return s return s
} }
@ -78,23 +78,23 @@ func (r *updateSimulationModelRequest) updatedSimulationModel(oldSimulationModel
// Use the old SimulationModel as a basis for the updated Simulation model // Use the old SimulationModel as a basis for the updated Simulation model
s := oldSimulationModel s := oldSimulationModel
if r.Model.Name != "" { if r.SimulationModel.Name != "" {
s.Name = r.Model.Name s.Name = r.SimulationModel.Name
} }
if r.Model.SimulatorID != 0 { if r.SimulationModel.SimulatorID != 0 {
s.SimulatorID = r.Model.SimulatorID s.SimulatorID = r.SimulationModel.SimulatorID
} }
// only update Params if not empty // only update Params if not empty
var emptyJson postgres.Jsonb var emptyJson postgres.Jsonb
// Serialize empty json and params // Serialize empty json and params
emptyJson_ser, _ := json.Marshal(emptyJson) emptyJson_ser, _ := json.Marshal(emptyJson)
startParams_ser, _ := json.Marshal(r.Model.StartParameters) startParams_ser, _ := json.Marshal(r.SimulationModel.StartParameters)
opts := jsondiff.DefaultConsoleOptions() opts := jsondiff.DefaultConsoleOptions()
diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts) diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts)
if diff.String() != "FullMatch" { if diff.String() != "FullMatch" {
s.StartParameters = r.Model.StartParameters s.StartParameters = r.SimulationModel.StartParameters
} }
return s return s

View file

@ -227,7 +227,7 @@ func getModelsOfSimulator(c *gin.Context) {
// get all associated simulation models // get all associated simulation models
allModels, _, err := s.getModels() allModels, _, err := s.getModels()
if !helper.DBError(c, err) { if !helper.DBError(c, err) {
c.JSON(http.StatusOK, gin.H{"models": allModels}) c.JSON(http.StatusOK, gin.H{"simulationModels": allModels})
} }
} }