Files
query-orchestration/internal/query/create.go
T
2025-01-07 13:55:23 +00:00

40 lines
964 B
Go

package query
import (
"context"
"fmt"
contextfull "queryorchestration/internal/contextFull"
jsonextractor "queryorchestration/internal/jsonExtractor"
queryprocessor "queryorchestration/internal/queryProcessor"
"github.com/google/uuid"
)
func (s *Service) Create(ctx context.Context, entity *queryprocessor.Create) (uuid.UUID, error) {
validator, err := s.getCreator(entity.Type)
if err != nil {
return uuid.Nil, err
}
err = validator.Validate(ctx, entity)
if err != nil {
return uuid.Nil, err
}
// TODO - submit create - type, requiredids, config
id := uuid.New()
return id, nil
}
func (s *Service) getCreator(qType queryprocessor.Type) (queryprocessor.Creator, error) {
switch qType {
case queryprocessor.TypeJsonExtractor:
return jsonextractor.NewCreator(s.db), nil
case queryprocessor.TypeContextFull:
return contextfull.NewCreator(s.db), nil
default:
return nil, fmt.Errorf("attempting to process invalid query type")
}
}