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

54 lines
1.0 KiB
Go
Raw Normal View History

package docinitrunner
2024-12-18 18:54:48 +00:00
import (
"context"
"log/slog"
2025-03-05 12:05:46 +00:00
"queryorchestration/internal/document"
documentinit "queryorchestration/internal/document/init"
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
)
const Name = "docInitRunner"
type Services struct {
Document *documentinit.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 {
Bucket string `json:"bucket" validate:"required"`
Key string `json:"key" validate:"required"`
Hash string `json:"hash" validate:"required"`
ClientID string `json:"clientId" validate:"required"`
}
func (s Runner) Process(ctx context.Context, body Body) bool {
id, err := s.svc.Document.Create(ctx, &documentinit.Create{
ClientID: body.ClientID,
Location: document.Location{
Bucket: body.Bucket,
Key: body.Key,
},
Hash: body.Hash,
})
if err != nil {
return false
2024-12-18 18:54:48 +00:00
}
slog.Debug("created document", "id", id)
2024-12-18 18:54:48 +00:00
return true
}