50 lines
1.1 KiB
Go
50 lines
1.1 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
|
|
ActiveVersion int32
|
|
LatestVersion int32
|
|
RequiredQueryIDs []uuid.UUID
|
|
Config string
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
return ParseDBGetQuery(&query)
|
|
}
|
|
|
|
func ParseDBGetQuery(q *repository.GetQueryRow) (*Query, error) {
|
|
reqQueryIDs := make([]uuid.UUID, len(q.Requiredids))
|
|
for index, id := range q.Requiredids {
|
|
reqQueryIDs[index] = database.MustToUUID(id)
|
|
}
|
|
|
|
qType, err := queryprocessor.ParseDBType(q.Type)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Query{
|
|
ID: database.MustToUUID(q.ID),
|
|
ActiveVersion: q.Activeversion,
|
|
LatestVersion: q.Latestversion,
|
|
Type: qType,
|
|
RequiredQueryIDs: reqQueryIDs,
|
|
Config: string(q.Config),
|
|
}, nil
|
|
}
|