2025-01-03 14:21:14 +00:00
|
|
|
package query
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-05 12:05:46 +00:00
|
|
|
|
2025-01-03 14:21:14 +00:00
|
|
|
"queryorchestration/internal/database/repository"
|
2025-01-29 11:52:37 +00:00
|
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
2025-01-03 14:21:14 +00:00
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Query struct {
|
|
|
|
|
ID uuid.UUID
|
2025-01-29 11:52:37 +00:00
|
|
|
Type resultprocessor.Type
|
2025-01-03 14:21:14 +00:00
|
|
|
ActiveVersion int32
|
|
|
|
|
LatestVersion int32
|
2025-01-20 13:31:48 +00:00
|
|
|
RequiredQueryIDs *[]uuid.UUID
|
|
|
|
|
Config *string
|
2025-01-03 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
func (s *Service) GetWithVersion(ctx context.Context, id uuid.UUID, version int32) (*Query, error) {
|
2025-01-31 13:43:55 +00:00
|
|
|
query, err := s.cfg.GetDBQueries().GetQueryWithVersion(ctx, &repository.GetQueryWithVersionParams{
|
2025-03-20 11:06:41 +00:00
|
|
|
ID: &id,
|
2025-02-14 10:56:24 +00:00
|
|
|
Version: &version,
|
2025-01-29 11:52:37 +00:00
|
|
|
})
|
2025-01-03 14:21:14 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
return ParseQueryWithVersion(query)
|
2025-01-03 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Query, error) {
|
2025-03-20 11:06:41 +00:00
|
|
|
query, err := s.cfg.GetDBQueries().GetQuery(ctx, id)
|
2025-01-03 14:21:14 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
return ParseFullActiveQuery(query)
|
2025-01-15 12:19:49 +00:00
|
|
|
}
|