Files
query-orchestration/api/queryRunner/queryrunner.go
T
Jay Brown 174644b63c Merged in jb/openapi (pull request #22)
add openapi infra

* add openapi infra

Includes generated stubs and all deps

* generatetolocation

* basesetupoffunctionsandclient

* round1controllertests

* passintegrationtests

* cleanupfromfullsuite

* storedjson

* fixjsonyaml

* fixtests


Approved-by: Michael McGuinness
2025-01-15 19:45:51 +00:00

65 lines
1.2 KiB
Go

package controllers
import (
"context"
"encoding/json"
"queryorchestration/internal/document"
"queryorchestration/internal/queue"
"github.com/go-playground/validator/v10"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
"github.com/google/uuid"
)
type QueryRunner struct {
validator *validator.Validate
document *document.Service
}
func NewQueryRunner(svc *document.Service, validator *validator.Validate) QueryRunner {
return QueryRunner{
validator: validator,
document: svc,
}
}
type DocumentQueryEvent struct {
ID uuid.UUID `json:"id"`
}
func (s QueryRunner) Process(ctx context.Context, config *queue.Config, msg *types.Message) error {
var body document.Document
err := json.Unmarshal([]byte(*msg.Body), &body)
if err != nil {
return err
}
err = s.validator.Struct(body)
if err != nil {
return err
}
err = s.document.Sync(ctx, &body)
if err != nil {
return err
}
queryEvent := DocumentQueryEvent{
ID: body.ID,
}
err = queue.Send(ctx, config, queryEvent, map[string]types.MessageAttributeValue{
"type": {
DataType: aws.String("String"),
StringValue: aws.String("DOCQUERY"),
},
})
if err != nil {
return err
}
return nil
}