Files
query-orchestration/api/queue/document.go
T

55 lines
959 B
Go
Raw Normal View History

2024-12-18 18:54:48 +00:00
package queue
import (
"context"
"encoding/json"
"gotemplate/internal/document"
"gotemplate/internal/queue"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
"github.com/google/uuid"
2024-12-18 18:54:48 +00:00
)
type DocumentController struct {
document document.Service
}
func NewDocumentController(svc document.Service) *DocumentController {
return &DocumentController{
document: svc,
}
}
type DocumentQueryEvent struct {
ID uuid.UUID `json:"id"`
2024-12-18 18:54:48 +00:00
}
func (s *DocumentController) Sync(ctx context.Context, config *queue.QueueConfig, msg *types.Message) error {
var body document.Document
err := json.Unmarshal([]byte(*msg.Body), &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, "DOCQUERY", queryEvent)
if err != nil {
return err
}
err = queue.Delete(ctx, config, msg)
if err != nil {
return err
}
return nil
}