优化结构
This commit is contained in:
@@ -2,7 +2,6 @@ package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
integrationbiz "kra/internal/biz/integration"
|
||||
)
|
||||
|
||||
type IntegrationConfigRequest struct {
|
||||
@@ -11,12 +10,28 @@ type IntegrationConfigRequest struct {
|
||||
}
|
||||
|
||||
type IntegrationConfigResponse struct {
|
||||
Kind string `json:"kind"`
|
||||
Provider string `json:"provider"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Configured bool `json:"configured"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
Fields []integrationbiz.IntegrationConfigField `json:"fields"`
|
||||
Kind string `json:"kind"`
|
||||
Provider string `json:"provider"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Configured bool `json:"configured"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
Fields []IntegrationConfigField `json:"fields"`
|
||||
}
|
||||
|
||||
type IntegrationConfigField struct {
|
||||
Key string `json:"key"`
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type"`
|
||||
Required bool `json:"required"`
|
||||
Secret bool `json:"secret"`
|
||||
Placeholder string `json:"placeholder,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Options []IntegrationConfigOption `json:"options,omitempty"`
|
||||
}
|
||||
|
||||
type IntegrationConfigOption struct {
|
||||
Label string `json:"label"`
|
||||
Value any `json:"value"`
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*dt
|
||||
enabled = config.Enabled
|
||||
delete(byProvider, definition.Provider)
|
||||
}
|
||||
result = append(result, &dto.IntegrationConfigResponse{Kind: definition.Kind, Provider: definition.Provider, Name: definition.Name, Description: definition.Description, Enabled: enabled, Configured: configured, Config: values, Fields: definition.Fields})
|
||||
result = append(result, &dto.IntegrationConfigResponse{Kind: definition.Kind, Provider: definition.Provider, Name: definition.Name, Description: definition.Description, Enabled: enabled, Configured: configured, Config: values, Fields: integrationFieldsDTO(definition.Fields)})
|
||||
}
|
||||
for _, config := range configs {
|
||||
if _, exists := byProvider[config.Provider]; !exists {
|
||||
@@ -59,7 +59,7 @@ func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider stri
|
||||
if found {
|
||||
response.Name = definition.Name
|
||||
response.Description = definition.Description
|
||||
response.Fields = definition.Fields
|
||||
response.Fields = integrationFieldsDTO(definition.Fields)
|
||||
response.Config = mergeConfigJSON(definition.Defaults, config.Values)
|
||||
}
|
||||
return response, nil
|
||||
@@ -90,3 +90,21 @@ func mergeConfigJSON(defaults map[string]any, raw json.RawMessage) json.RawMessa
|
||||
encoded, _ := json.Marshal(values)
|
||||
return encoded
|
||||
}
|
||||
|
||||
func integrationFieldsDTO(fields []integrationbiz.IntegrationConfigField) []dto.IntegrationConfigField {
|
||||
if fields == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]dto.IntegrationConfigField, 0, len(fields))
|
||||
for _, field := range fields {
|
||||
item := dto.IntegrationConfigField{Key: field.Key, Label: field.Label, Type: field.Type, Required: field.Required, Secret: field.Secret, Placeholder: field.Placeholder, Description: field.Description}
|
||||
if field.Options != nil {
|
||||
item.Options = make([]dto.IntegrationConfigOption, 0, len(field.Options))
|
||||
for _, option := range field.Options {
|
||||
item.Options = append(item.Options, dto.IntegrationConfigOption{Label: option.Label, Value: option.Value})
|
||||
}
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user