15adaebfcd
DRAFT PR : WIP working through ideas for integration * movearound * attempttwo * openapi * further sanding * fix * start on tests * runthroughsingleconfig * somechanges * reflectissue * removeerrs * mostlyremovepanic * removeenv * noncfgtests * go * repo * fix service config test * add PWD to all * test fix * fix lint * todo for later * passingunittests * alltests * testlogger * testloggername * clean
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package result
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"queryorchestration/internal/database"
|
|
"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
|
|
MinCleanVersion int32
|
|
MinTextVersion int32
|
|
}
|
|
|
|
func (s *Service) GetValueWithVersion(ctx context.Context, params *GetValueWithVersionParams) (resultprocessor.Value, error) {
|
|
res, err := s.cfg.GetDBQueries().GetResultValueWithVersion(ctx, &repository.GetResultValueWithVersionParams{
|
|
Queryid: database.MustToDBUUID(params.QueryID),
|
|
Queryversion: params.QueryVersion,
|
|
Documentid: database.MustToDBUUID(params.DocumentID),
|
|
Cleanversion: params.MinCleanVersion,
|
|
Textversion: params.MinTextVersion,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|