refactor: organize service dto contracts

This commit is contained in:
Yvan
2026-08-21 14:00:19 +08:00
parent e81a641953
commit d91f0554fd
65 changed files with 865 additions and 696 deletions
+8 -7
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"kra/internal/biz"
"kra/internal/service/dto"
)
type IntegrationConfigService struct{ uc *biz.IntegrationConfigUsecase }
@@ -13,7 +14,7 @@ func NewIntegrationConfigService(uc *biz.IntegrationConfigUsecase) *IntegrationC
return &IntegrationConfigService{uc: uc}
}
func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*IntegrationConfigResponse, error) {
func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*dto.IntegrationConfigResponse, error) {
configs, err := s.uc.List(ctx, kind)
if err != nil {
return nil, err
@@ -25,7 +26,7 @@ func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*In
}
}
definitions := biz.IntegrationDefinitions(kind)
result := make([]*IntegrationConfigResponse, 0, len(definitions)+len(configs))
result := make([]*dto.IntegrationConfigResponse, 0, len(definitions)+len(configs))
for _, definition := range definitions {
config, configured := byProvider[definition.Provider]
values := mergeConfigJSON(definition.Defaults, nil)
@@ -35,24 +36,24 @@ func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*In
enabled = config.Enabled
delete(byProvider, definition.Provider)
}
result = append(result, &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: definition.Fields})
}
for _, config := range configs {
if _, exists := byProvider[config.Provider]; !exists {
continue
}
result = append(result, &IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values})
result = append(result, &dto.IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values})
}
return result, nil
}
func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider string) (*IntegrationConfigResponse, error) {
func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider string) (*dto.IntegrationConfigResponse, error) {
config, err := s.uc.Find(ctx, kind, provider)
if err != nil {
return nil, err
}
definition, found := biz.IntegrationDefinition(config.Kind, config.Provider)
response := &IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values}
response := &dto.IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values}
if found {
response.Name = definition.Name
response.Description = definition.Description
@@ -62,7 +63,7 @@ func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider stri
return response, nil
}
func (s *IntegrationConfigService) Save(ctx context.Context, kind, provider string, req *IntegrationConfigRequest) error {
func (s *IntegrationConfigService) Save(ctx context.Context, kind, provider string, req *dto.IntegrationConfigRequest) error {
if req == nil {
return s.uc.Save(ctx, nil)
}