60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Query struct {
|
|
ID uuid.UUID
|
|
Type queryprocessor.Type
|
|
RequiredQueryIDs []uuid.UUID
|
|
Version int32
|
|
Config interface{}
|
|
}
|
|
|
|
type ListFilters struct {
|
|
Types []queryprocessor.Type
|
|
}
|
|
|
|
type Test struct {
|
|
ID uuid.UUID
|
|
}
|
|
|
|
type Service struct {
|
|
db *repository.Queries
|
|
}
|
|
|
|
func New(db *repository.Queries) *Service {
|
|
return &Service{db}
|
|
}
|
|
|
|
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Query, error) {
|
|
query, err := s.db.GetQuery(ctx, database.MustToDBUUID(id))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
queryType, err := queryprocessor.ParseDBType(query.Type)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reqIDs := make([]uuid.UUID, len(query.Requiredids))
|
|
for index, id := range query.Requiredids {
|
|
reqIDs[index] = database.MustToUUID(id)
|
|
}
|
|
|
|
return &Query{
|
|
ID: id,
|
|
Type: queryType,
|
|
Version: query.Activeversion,
|
|
RequiredQueryIDs: reqIDs,
|
|
Config: string(query.Config),
|
|
}, nil
|
|
}
|