Files
query-orchestration/api/queryRunner/runner.go
T

59 lines
1.1 KiB
Go
Raw Normal View History

package queryrunner
2024-12-18 18:54:48 +00:00
import (
"context"
"encoding/json"
resultset "queryorchestration/internal/query/result/set"
2024-12-18 18:54:48 +00:00
2024-12-23 16:49:53 +00:00
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
2024-12-23 16:49:53 +00:00
2024-12-18 18:54:48 +00:00
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
)
const Name = "queryRunner"
type Services struct {
ResultSet *resultset.Service
}
type Runner struct {
2024-12-23 16:49:53 +00:00
validator *validator.Validate
svc *Services
2024-12-18 18:54:48 +00:00
}
func New(validator *validator.Validate, svc *Services) Runner {
return Runner{
2024-12-23 16:49:53 +00:00
validator: validator,
svc: svc,
2024-12-18 18:54:48 +00:00
}
}
type Body struct {
DocumentID uuid.UUID `json:"document_id" validate:"required,uuid"`
QueryID uuid.UUID `json:"query_id" validate:"required,uuid"`
}
func (s *Runner) Process(ctx context.Context, req *types.Message) error {
var body Body
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
err = s.svc.ResultSet.Set(ctx, &resultset.Set{
DocumentID: body.DocumentID,
QueryID: body.QueryID,
})
2024-12-18 18:54:48 +00:00
if err != nil {
return err
}
return nil
}