2025-01-03 13:41:07 +00:00
|
|
|
package query
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-01-03 14:21:14 +00:00
|
|
|
"queryorchestration/internal/database"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
2025-01-03 14:08:04 +00:00
|
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
2025-01-03 13:41:07 +00:00
|
|
|
)
|
|
|
|
|
|
2025-01-03 14:21:14 +00:00
|
|
|
type ListFilters struct {
|
|
|
|
|
Types []queryprocessor.Type
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 15:31:39 +00:00
|
|
|
func (s *Service) List(ctx context.Context, filters ListFilters) ([]*Query, error) {
|
2025-01-06 14:40:43 +00:00
|
|
|
// TODO - use filters
|
|
|
|
|
|
2025-01-06 12:26:28 +00:00
|
|
|
dbQueries, err := s.db.Queries.ListQueries(ctx)
|
2025-01-03 14:08:04 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 15:31:39 +00:00
|
|
|
queries := make([]*Query, len(dbQueries))
|
2025-01-03 14:08:04 +00:00
|
|
|
for index, query := range dbQueries {
|
2025-01-03 14:21:14 +00:00
|
|
|
q, err := ParseDBListQuery(&query)
|
2025-01-03 14:08:04 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 15:31:39 +00:00
|
|
|
queries[index] = q
|
2025-01-03 14:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 15:31:39 +00:00
|
|
|
return queries, nil
|
2025-01-03 13:41:07 +00:00
|
|
|
}
|
2025-01-03 14:21:14 +00:00
|
|
|
|
|
|
|
|
func ParseDBListQuery(q *repository.ListQueriesRow) (*Query, error) {
|
2025-01-06 15:31:39 +00:00
|
|
|
reqQueryIDs := database.MustToUUIDArray(q.Requiredids)
|
2025-01-03 14:21:14 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|