Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions platform-api/src/api/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions platform-api/src/internal/database/schema.postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ CREATE TABLE IF NOT EXISTS gateways (
description VARCHAR(1023),
properties JSONB NOT NULL DEFAULT '{}'::jsonb,
vhost VARCHAR(255) NOT NULL,
endpoints JSONB NOT NULL DEFAULT '[]'::jsonb,
is_critical BOOLEAN DEFAULT FALSE,
gateway_functionality_type VARCHAR(20) DEFAULT 'regular' NOT NULL,
is_active BOOLEAN DEFAULT FALSE,
Expand Down
1 change: 1 addition & 0 deletions platform-api/src/internal/database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ CREATE TABLE IF NOT EXISTS gateways (
description VARCHAR(1023),
properties TEXT NOT NULL DEFAULT '{}',
vhost VARCHAR(255) NOT NULL,
endpoints TEXT NOT NULL DEFAULT '[]',
is_critical BOOLEAN DEFAULT FALSE,
gateway_functionality_type VARCHAR(20) DEFAULT 'regular' NOT NULL,
is_active BOOLEAN DEFAULT FALSE,
Expand Down
1 change: 1 addition & 0 deletions platform-api/src/internal/database/schema.sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ CREATE TABLE IF NOT EXISTS gateways (
description VARCHAR(1023),
properties TEXT NOT NULL DEFAULT '{}',
vhost VARCHAR(255) NOT NULL,
endpoints TEXT NOT NULL DEFAULT '[]',
is_critical BOOLEAN DEFAULT FALSE,
gateway_functionality_type VARCHAR(20) DEFAULT 'regular' NOT NULL,
is_active BOOLEAN DEFAULT FALSE,
Expand Down
30 changes: 28 additions & 2 deletions platform-api/src/internal/handler/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"

"platform-api/src/internal/middleware"
"platform-api/src/internal/model"
"platform-api/src/internal/service"
"platform-api/src/internal/utils"

Expand Down Expand Up @@ -105,8 +106,20 @@ func (h *GatewayHandler) CreateGateway(c *gin.Context) {
return
}

var endpoints []model.GatewayEndpoint
if req.Endpoints != nil {
endpoints = make([]model.GatewayEndpoint, 0, len(*req.Endpoints))
for _, ep := range *req.Endpoints {
endpoints = append(endpoints, model.GatewayEndpoint{
Host: ep.Host,
Protocol: string(ep.Protocol),
Port: int(ep.Port),
})
}
}

gateway, err := h.gatewayService.RegisterGateway(orgId, req.Name, req.DisplayName, description, req.Vhost,
isCritical, functionalityType, version, properties)
isCritical, functionalityType, version, properties, endpoints)
if err != nil {
errMsg := err.Error()

Expand Down Expand Up @@ -262,7 +275,20 @@ func (h *GatewayHandler) UpdateGateway(c *gin.Context) {
return
}

response, err := h.gatewayService.UpdateGateway(gatewayId, orgId, req.Description, req.DisplayName, req.IsCritical, req.Properties)
var endpoints *[]model.GatewayEndpoint
if req.Endpoints != nil {
eps := make([]model.GatewayEndpoint, 0, len(*req.Endpoints))
for _, ep := range *req.Endpoints {
eps = append(eps, model.GatewayEndpoint{
Host: ep.Host,
Protocol: string(ep.Protocol),
Port: int(ep.Port),
})
}
endpoints = &eps
}

response, err := h.gatewayService.UpdateGateway(gatewayId, orgId, req.Description, req.DisplayName, req.IsCritical, req.Properties, endpoints)
if err != nil {
if errors.Is(err, constants.ErrGatewayNotFound) {
h.slogger.Error("Gateway not found during update", "error", err)
Expand Down
43 changes: 26 additions & 17 deletions platform-api/src/internal/model/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import (
"time"
)

// GatewayEndpoint represents a single host/protocol/port combination for a gateway
type GatewayEndpoint struct {
Host string `json:"host"`
Protocol string `json:"protocol"`
Port int `json:"port"`
}

// Gateway represents a registered gateway instance within an organization
type Gateway struct {
ID string `json:"id" db:"uuid"`
Expand All @@ -30,12 +37,13 @@ type Gateway struct {
Description string `json:"description" db:"description"`
Properties map[string]interface{} `json:"properties,omitempty" db:"properties"`
Vhost string `json:"vhost" db:"vhost"`
IsCritical bool `json:"isCritical" db:"is_critical"`
FunctionalityType string `json:"functionalityType" db:"gateway_functionality_type"`
Version string `json:"version" db:"version"`
IsActive bool `json:"isActive" db:"is_active"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
Endpoints []GatewayEndpoint `json:"endpoints" db:"endpoints"`
IsCritical bool `json:"isCritical" db:"is_critical"`
FunctionalityType string `json:"functionalityType" db:"gateway_functionality_type"`
Version string `json:"version" db:"version"`
IsActive bool `json:"isActive" db:"is_active"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}

// TableName returns the table name for the Gateway model
Expand Down Expand Up @@ -74,18 +82,19 @@ func (t *GatewayToken) Revoke() {
// APIGatewayWithDetails represents a gateway with its association and deployment details for an API
type APIGatewayWithDetails struct {
// Gateway information
ID string `json:"id" db:"id"`
OrganizationID string `json:"organizationId" db:"organization_id"`
Name string `json:"name" db:"name"`
DisplayName string `json:"displayName" db:"display_name"`
Description string `json:"description" db:"description"`
ID string `json:"id" db:"id"`
OrganizationID string `json:"organizationId" db:"organization_id"`
Name string `json:"name" db:"name"`
DisplayName string `json:"displayName" db:"display_name"`
Description string `json:"description" db:"description"`
Properties map[string]interface{} `json:"properties,omitempty" db:"properties"`
Vhost string `json:"vhost" db:"vhost"`
IsCritical bool `json:"isCritical" db:"is_critical"`
FunctionalityType string `json:"functionalityType" db:"functionality_type"`
IsActive bool `json:"isActive" db:"is_active"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
Vhost string `json:"vhost" db:"vhost"`
Endpoints []GatewayEndpoint `json:"endpoints" db:"endpoints"`
IsCritical bool `json:"isCritical" db:"is_critical"`
FunctionalityType string `json:"functionalityType" db:"functionality_type"`
IsActive bool `json:"isActive" db:"is_active"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`

// Association information
AssociatedAt time.Time `json:"associatedAt" db:"associated_at"`
Expand Down
Loading
Loading