0ebb8a21a1
Clean Up Testing and Linting * somescriptcleanup * mostgolangci * deplatest * imageversions * usingscratch * movedqueuefrtesting * finishedunittesting * linting * taskfilecontext
65 lines
1.2 KiB
Go
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
|
|
}
|