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
53 lines
895 B
Go
53 lines
895 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"queryorchestration/internal/query"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Services struct {
|
|
Query *query.Service
|
|
}
|
|
|
|
type QueryRunner struct {
|
|
validator *validator.Validate
|
|
svc *Services
|
|
}
|
|
|
|
func NewQueryRunner(validator *validator.Validate, svc *Services) QueryRunner {
|
|
return QueryRunner{
|
|
validator: validator,
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
type DocumentQueryEvent struct {
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (s *QueryRunner) Process(ctx context.Context, req *types.Message) error {
|
|
var body query.Document
|
|
err := json.Unmarshal([]byte(*req.Body), &body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = s.validator.Struct(body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = s.svc.Query.Sync(ctx, &body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|