From aea28c712e8d233c22a5b1ead0114443c7fd9c9a Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Fri, 26 Jun 2020 10:02:57 +0200 Subject: [PATCH] add APIHost parameter to IC data model #35 --- database/models.go | 2 ++ doc/api/docs.go | 12 +++++++++++- doc/api/swagger.json | 10 ++++++++++ doc/api/swagger.yaml | 7 +++++++ routes/infrastructure-component/ic_test.go | 1 + routes/infrastructure-component/ic_validators.go | 7 +++++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/database/models.go b/database/models.go index 970f5c4..8bf5331 100644 --- a/database/models.go +++ b/database/models.go @@ -120,6 +120,8 @@ type InfrastructureComponent struct { Name string `json:"name" gorm:"default:''"` // Host if the IC Host string `json:"host" gorm:"default:''"` + // Host of API for IC + APIHost string `json:"apihost" gorm:"default:''"` // Category of IC (simulator, gateway, database, etc.) Category string `json:"category" gorm:"default:''"` // Type of IC (RTDS, VILLASnode, RTDS, etc.) diff --git a/doc/api/docs.go b/doc/api/docs.go index fea7323..46f777f 100644 --- a/doc/api/docs.go +++ b/doc/api/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-06-26 09:42:08.437454207 +0200 CEST m=+0.080918529 +// 2020-06-26 09:52:23.901926224 +0200 CEST m=+0.077245770 package docs @@ -3058,6 +3058,10 @@ var doc = `{ "database.InfrastructureComponent": { "type": "object", "properties": { + "apihost": { + "description": "Host of API for IC", + "type": "string" + }, "category": { "description": "Category of IC (simulator, gateway, database, etc.)", "type": "string" @@ -3452,6 +3456,9 @@ var doc = `{ "UUID" ], "properties": { + "APIHost": { + "type": "string" + }, "Category": { "type": "string" }, @@ -3478,6 +3485,9 @@ var doc = `{ "infrastructure_component.validUpdatedIC": { "type": "object", "properties": { + "APIHost": { + "type": "string" + }, "Category": { "type": "string" }, diff --git a/doc/api/swagger.json b/doc/api/swagger.json index 6129aae..a4c4749 100644 --- a/doc/api/swagger.json +++ b/doc/api/swagger.json @@ -3041,6 +3041,10 @@ "database.InfrastructureComponent": { "type": "object", "properties": { + "apihost": { + "description": "Host of API for IC", + "type": "string" + }, "category": { "description": "Category of IC (simulator, gateway, database, etc.)", "type": "string" @@ -3435,6 +3439,9 @@ "UUID" ], "properties": { + "APIHost": { + "type": "string" + }, "Category": { "type": "string" }, @@ -3461,6 +3468,9 @@ "infrastructure_component.validUpdatedIC": { "type": "object", "properties": { + "APIHost": { + "type": "string" + }, "Category": { "type": "string" }, diff --git a/doc/api/swagger.yaml b/doc/api/swagger.yaml index a715673..4e3ef4b 100644 --- a/doc/api/swagger.yaml +++ b/doc/api/swagger.yaml @@ -142,6 +142,9 @@ definitions: type: object database.InfrastructureComponent: properties: + apihost: + description: Host of API for IC + type: string category: description: Category of IC (simulator, gateway, database, etc.) type: string @@ -408,6 +411,8 @@ definitions: type: object infrastructure_component.validNewIC: properties: + APIHost: + type: string Category: type: string Host: @@ -431,6 +436,8 @@ definitions: type: object infrastructure_component.validUpdatedIC: properties: + APIHost: + type: string Category: type: string Host: diff --git a/routes/infrastructure-component/ic_test.go b/routes/infrastructure-component/ic_test.go index 92abc5e..178fb9b 100644 --- a/routes/infrastructure-component/ic_test.go +++ b/routes/infrastructure-component/ic_test.go @@ -41,6 +41,7 @@ var router *gin.Engine type ICRequest struct { UUID string `json:"uuid,omitempty"` Host string `json:"host,omitempty"` + APIHost string `json:"apihost,omitempty"` Type string `json:"type,omitempty"` Name string `json:"name,omitempty"` Category string `json:"category,omitempty"` diff --git a/routes/infrastructure-component/ic_validators.go b/routes/infrastructure-component/ic_validators.go index dee0b78..edb84f5 100644 --- a/routes/infrastructure-component/ic_validators.go +++ b/routes/infrastructure-component/ic_validators.go @@ -33,6 +33,7 @@ var validate *validator.Validate type validNewIC struct { UUID string `form:"UUID" validate:"required"` Host string `form:"Host" validate:"required"` + APIHost string `form:"APIHost" validate:"omitempty"` Type string `form:"Type" validate:"required"` Name string `form:"Name" validate:"required"` Category string `form:"Category" validate:"required"` @@ -43,6 +44,7 @@ type validNewIC struct { type validUpdatedIC struct { UUID string `form:"UUID" validate:"omitempty"` Host string `form:"Host" validate:"omitempty"` + APIHost string `form:"APIHost" validate:"omitempty"` Type string `form:"Type" validate:"omitempty"` Name string `form:"Name" validate:"omitempty"` Category string `form:"Category" validate:"omitempty"` @@ -75,6 +77,7 @@ func (r *addICRequest) createIC() InfrastructureComponent { s.UUID = r.InfrastructureComponent.UUID s.Host = r.InfrastructureComponent.Host + s.APIHost = r.InfrastructureComponent.APIHost s.Type = r.InfrastructureComponent.Type s.Name = r.InfrastructureComponent.Name s.Category = r.InfrastructureComponent.Category @@ -97,6 +100,10 @@ func (r *updateICRequest) updatedIC(oldIC InfrastructureComponent) Infrastructur s.Host = r.InfrastructureComponent.Host } + if r.InfrastructureComponent.APIHost != "" { + s.APIHost = r.InfrastructureComponent.APIHost + } + if r.InfrastructureComponent.Type != "" { s.Type = r.InfrastructureComponent.Type }