Add platform status switch
This commit is contained in:
@@ -182,10 +182,15 @@ func (s *Server) createPlatform(w http.ResponseWriter, r *http.Request) {
|
||||
input.Provider = strings.TrimSpace(input.Provider)
|
||||
input.Name = strings.TrimSpace(input.Name)
|
||||
input.InternalName = strings.TrimSpace(input.InternalName)
|
||||
input.Status = strings.TrimSpace(input.Status)
|
||||
if input.Provider == "" || input.Name == "" {
|
||||
writeError(w, http.StatusBadRequest, "provider and name are required")
|
||||
return
|
||||
}
|
||||
if input.Status != "" && input.Status != "enabled" && input.Status != "disabled" {
|
||||
writeError(w, http.StatusBadRequest, "status must be enabled or disabled")
|
||||
return
|
||||
}
|
||||
if input.AuthType == "" {
|
||||
input.AuthType = "bearer"
|
||||
}
|
||||
@@ -213,10 +218,15 @@ func (s *Server) updatePlatform(w http.ResponseWriter, r *http.Request) {
|
||||
input.Provider = strings.TrimSpace(input.Provider)
|
||||
input.Name = strings.TrimSpace(input.Name)
|
||||
input.InternalName = strings.TrimSpace(input.InternalName)
|
||||
input.Status = strings.TrimSpace(input.Status)
|
||||
if input.Provider == "" || input.Name == "" {
|
||||
writeError(w, http.StatusBadRequest, "provider and name are required")
|
||||
return
|
||||
}
|
||||
if input.Status != "" && input.Status != "enabled" && input.Status != "disabled" {
|
||||
writeError(w, http.StatusBadRequest, "status must be enabled or disabled")
|
||||
return
|
||||
}
|
||||
if input.AuthType == "" {
|
||||
input.AuthType = "bearer"
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ type CreatePlatformInput struct {
|
||||
DefaultDiscountFactor float64 `json:"defaultDiscountFactor"`
|
||||
PricingRuleSetID string `json:"pricingRuleSetId"`
|
||||
Priority int `json:"priority"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type CreateAPIKeyInput struct {
|
||||
@@ -591,11 +592,11 @@ func (s *Store) CreatePlatform(ctx context.Context, input CreatePlatformInput) (
|
||||
INSERT INTO integration_platforms (
|
||||
provider, platform_key, name, internal_name, base_url, auth_type, credentials, config,
|
||||
default_pricing_mode, default_discount_factor, pricing_rule_set_id,
|
||||
priority, retry_policy, rate_limit_policy
|
||||
priority, retry_policy, rate_limit_policy, status
|
||||
)
|
||||
VALUES (
|
||||
$1, COALESCE(NULLIF($2, ''), 'platform_' || replace(gen_random_uuid()::text, '-', '')), $3, NULLIF($4, ''), $5, $6, $7, $8,
|
||||
$9, $10, NULLIF($11, '')::uuid, $12, $13, $14
|
||||
$9, $10, NULLIF($11, '')::uuid, $12, $13, $14, COALESCE(NULLIF($15, ''), 'enabled')
|
||||
)
|
||||
RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status,
|
||||
priority, dynamic_priority, COALESCE(dynamic_priority, priority),
|
||||
@@ -606,6 +607,7 @@ RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), C
|
||||
input.Provider, input.PlatformKey, input.Name, strings.TrimSpace(input.InternalName), input.BaseURL, input.AuthType, credentials, config,
|
||||
input.DefaultPricingMode, input.DefaultDiscountFactor, input.PricingRuleSetID, input.Priority,
|
||||
string(retryPolicy), string(rateLimitPolicy),
|
||||
input.Status,
|
||||
).Scan(
|
||||
&platform.ID,
|
||||
&platform.Provider,
|
||||
@@ -684,6 +686,7 @@ SET provider = $2,
|
||||
priority = $13,
|
||||
retry_policy = $14,
|
||||
rate_limit_policy = $15,
|
||||
status = COALESCE(NULLIF($16, ''), status),
|
||||
updated_at = now()
|
||||
WHERE id = $1::uuid
|
||||
RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status,
|
||||
@@ -707,6 +710,7 @@ RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), C
|
||||
input.Priority,
|
||||
string(retryPolicy),
|
||||
string(rateLimitPolicy),
|
||||
input.Status,
|
||||
).Scan(
|
||||
&platform.ID,
|
||||
&platform.Provider,
|
||||
|
||||
Reference in New Issue
Block a user