46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
contextfull "queryorchestration/internal/contextFull"
|
|
"queryorchestration/internal/database"
|
|
jsonextractor "queryorchestration/internal/jsonExtractor"
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
|
)
|
|
|
|
func (s *Service) Update(ctx context.Context, entity *queryprocessor.Update) error {
|
|
dbType, err := s.db.GetQueryType(ctx, database.MustToDBUUID(entity.ID))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
qType, err := queryprocessor.ParseDBType(dbType)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
validator, err := s.getUpdator(qType)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = validator.Update(ctx, entity)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|