package query import ( "context" "fmt" contextfull "queryorchestration/internal/contextFull" jsonextractor "queryorchestration/internal/jsonExtractor" queryprocessor "queryorchestration/internal/queryProcessor" ) func (s *Service) Update(ctx context.Context, entity *queryprocessor.Update) error { current, err := s.Get(ctx, entity.ID) if err != nil { return err } validator, err := s.getUpdator(current.Type) if err != nil { return err } err = validator.Validate(ctx, ParseQuery(current), entity) if err != nil { return err } // TODO - generate new entity // TODO - submit update - id, type, activeversion, requiredQueryId, Config return nil } func (s *Service) getUpdator(qType queryprocessor.Type) (queryprocessor.Updator, error) { switch qType { case queryprocessor.TypeJsonExtractor: return jsonextractor.NewUpdator(s.db), nil case queryprocessor.TypeContextFull: return contextfull.NewUpdator(s.db), nil default: return nil, fmt.Errorf("attempting to process invalid query type") } } func ParseQuery(q *Query) *queryprocessor.Query { return &queryprocessor.Query{ ID: q.ID, Type: q.Type, Version: q.ActiveVersion, RequiredQueryIDs: q.RequiredQueryIDs, Config: q.Config, } }