37 lines
895 B
Go
37 lines
895 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
|
|
}
|
|
|
|
id, err := validator.Create(ctx, entity)
|
|
if err != nil {
|
|
return uuid.Nil, err
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|