b16ff55afa
Document CRUD * doccreate * dochashlocandget * depsandtodo
53 lines
943 B
Go
53 lines
943 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
documentsync "queryorchestration/internal/document/sync"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Services struct {
|
|
DocumentSync *documentsync.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 documentsync.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.DocumentSync.Sync(ctx, &body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|