53ea7d34e6
Start adding Textract + UUID changes * base * startclient * ts * short * tests
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package result
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
contextfull "queryorchestration/internal/query/types/contextFull"
|
|
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type GetValueWithVersionParams struct {
|
|
Type resultprocessor.Type
|
|
QueryID uuid.UUID
|
|
DocumentID uuid.UUID
|
|
QueryVersion int32
|
|
}
|
|
|
|
func (s *Service) GetValueWithVersion(ctx context.Context, params *GetValueWithVersionParams) (resultprocessor.Value, error) {
|
|
res, err := s.cfg.GetDBQueries().GetResultValueWithVersion(ctx, &repository.GetResultValueWithVersionParams{
|
|
Queryid: ¶ms.QueryID,
|
|
Queryversion: ¶ms.QueryVersion,
|
|
Documentid: ¶ms.DocumentID,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if res.Value == nil {
|
|
return nil, errors.New("no value found")
|
|
}
|
|
|
|
return getValueByType(params.Type, *res.Value)
|
|
}
|
|
|
|
func getValueByType(t resultprocessor.Type, value string) (resultprocessor.Value, error) {
|
|
switch t {
|
|
case resultprocessor.TypeJsonExtractor:
|
|
return jsonextractor.NewResult(value), nil
|
|
case resultprocessor.TypeContextFull:
|
|
return contextfull.NewResult(value), nil
|
|
default:
|
|
return nil, fmt.Errorf("attempting to process invalid query type")
|
|
}
|
|
}
|