2025-01-10 11:12:03 +00:00
|
|
|
package controllers
|
2024-12-18 18:54:48 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2025-01-24 16:12:25 +00:00
|
|
|
documentsync "queryorchestration/internal/document/sync"
|
2024-12-18 18:54:48 +00:00
|
|
|
|
2024-12-23 16:49:53 +00:00
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
|
|
2024-12-18 18:54:48 +00:00
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
2024-12-19 18:49:22 +00:00
|
|
|
"github.com/google/uuid"
|
2024-12-18 18:54:48 +00:00
|
|
|
)
|
|
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
type Services struct {
|
|
|
|
|
DocumentSync *documentsync.Service
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-10 11:12:03 +00:00
|
|
|
type QueryRunner struct {
|
2024-12-23 16:49:53 +00:00
|
|
|
validator *validator.Validate
|
2025-01-24 16:12:25 +00:00
|
|
|
svc *Services
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
func NewQueryRunner(validator *validator.Validate, svc *Services) QueryRunner {
|
2025-01-10 11:12:03 +00:00
|
|
|
return QueryRunner{
|
2024-12-23 16:49:53 +00:00
|
|
|
validator: validator,
|
2025-01-24 16:12:25 +00:00
|
|
|
svc: svc,
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DocumentQueryEvent struct {
|
2024-12-19 18:49:22 +00:00
|
|
|
ID uuid.UUID `json:"id"`
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-20 13:51:22 +00:00
|
|
|
func (s QueryRunner) Process(ctx context.Context, req *types.Message) error {
|
2025-01-24 16:12:25 +00:00
|
|
|
var body documentsync.Document
|
2025-01-20 13:51:22 +00:00
|
|
|
err := json.Unmarshal([]byte(*req.Body), &body)
|
2024-12-18 18:54:48 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 16:49:53 +00:00
|
|
|
err = s.validator.Struct(body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2024-12-20 17:35:33 +00:00
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
err = s.svc.DocumentSync.Sync(ctx, &body)
|
2024-12-18 18:54:48 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|