b888e3450f
Remove Queue Controller Config * removeout
49 lines
873 B
Go
49 lines
873 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"queryorchestration/internal/query/document"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
"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, req *types.Message) error {
|
|
var body document.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.document.Sync(ctx, &body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|