Merged in bugfix/cleanup (pull request #10)
Clean Up Testing and Linting * somescriptcleanup * mostgolangci * deplatest * imageversions * usingscratch * movedqueuefrtesting * finishedunittesting * linting * taskfilecontext
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user