controllersupdate
This commit is contained in:
@@ -15,8 +15,10 @@ func ParseQuery(query *query.Query) *serviceinterfaces.Query {
|
||||
return &serviceinterfaces.Query{
|
||||
Id: query.ID.String(),
|
||||
Type: ParseQueryType(query.Type),
|
||||
ActiveVersion: query.Version,
|
||||
ActiveVersion: query.ActiveVersion,
|
||||
LatestVersion: query.LatestVersion,
|
||||
RequiredQueries: requiredQueries,
|
||||
Config: &query.Config,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,13 +120,19 @@ func (s *QueryController) Deprecate(ctx context.Context, req *spec.IdMessage) (*
|
||||
}
|
||||
|
||||
func (s *QueryController) Test(ctx context.Context, req *serviceinterfaces.QueryTestRequest) (*serviceinterfaces.QueryTestResponse, error) {
|
||||
id, err := uuid.Parse(req.GetId())
|
||||
queryId, err := uuid.Parse(req.GetQueryId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
docId, err := uuid.Parse(req.GetDocumentId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
value, err := s.query.Test(ctx, query.Test{
|
||||
ID: id,
|
||||
QueryID: queryId,
|
||||
QueryVersion: req.GetQueryVersion(),
|
||||
DocumentID: docId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+1
-1
Submodule api/serviceInterfaces updated: e3d7e63a27...6da8d1c276
@@ -13,7 +13,7 @@ SELECT EXISTS (
|
||||
);
|
||||
|
||||
-- name: GetQuery :one
|
||||
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
@@ -25,7 +25,7 @@ SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS
|
||||
GROUP BY q.id, c.config;
|
||||
|
||||
-- name: ListQueries :many
|
||||
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
|
||||
@@ -21,7 +21,7 @@ func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error
|
||||
}
|
||||
|
||||
const getQuery = `-- name: GetQuery :one
|
||||
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
@@ -37,6 +37,7 @@ type GetQueryRow struct {
|
||||
ID pgtype.UUID
|
||||
Type Querytype
|
||||
Activeversion int32
|
||||
Latestversion int32
|
||||
Config []byte
|
||||
Requiredids []pgtype.UUID
|
||||
}
|
||||
@@ -48,6 +49,7 @@ func (q *Queries) GetQuery(ctx context.Context, id pgtype.UUID) (GetQueryRow, er
|
||||
&i.ID,
|
||||
&i.Type,
|
||||
&i.Activeversion,
|
||||
&i.Latestversion,
|
||||
&i.Config,
|
||||
&i.Requiredids,
|
||||
)
|
||||
@@ -100,7 +102,7 @@ func (q *Queries) IsQueryDeprecated(ctx context.Context, queryid pgtype.UUID) (b
|
||||
}
|
||||
|
||||
const listQueries = `-- name: ListQueries :many
|
||||
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
@@ -115,6 +117,7 @@ type ListQueriesRow struct {
|
||||
ID pgtype.UUID
|
||||
Type Querytype
|
||||
Activeversion int32
|
||||
Latestversion int32
|
||||
Config []byte
|
||||
Requiredids []pgtype.UUID
|
||||
}
|
||||
@@ -132,6 +135,7 @@ func (q *Queries) ListQueries(ctx context.Context) ([]ListQueriesRow, error) {
|
||||
&i.ID,
|
||||
&i.Type,
|
||||
&i.Activeversion,
|
||||
&i.Latestversion,
|
||||
&i.Config,
|
||||
&i.Requiredids,
|
||||
); err != nil {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
+32
-3
@@ -2,18 +2,26 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
queryprocessor "queryorchestration/internal/queryProcessor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) List(ctx context.Context, filters ListFilters) (*[]queryprocessor.Query, error) {
|
||||
type ListFilters struct {
|
||||
Types []queryprocessor.Type
|
||||
}
|
||||
|
||||
func (s *Service) List(ctx context.Context, filters ListFilters) (*[]Query, error) {
|
||||
dbQueries, err := s.db.ListQueries(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queries := make([]queryprocessor.Query, len(dbQueries))
|
||||
queries := make([]Query, len(dbQueries))
|
||||
for index, query := range dbQueries {
|
||||
q, err := queryprocessor.ParseDBListQuery(&query)
|
||||
q, err := ParseDBListQuery(&query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23,3 +31,24 @@ func (s *Service) List(ctx context.Context, filters ListFilters) (*[]queryproces
|
||||
|
||||
return &queries, nil
|
||||
}
|
||||
|
||||
func ParseDBListQuery(q *repository.ListQueriesRow) (*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
|
||||
}
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
queryprocessor "queryorchestration/internal/queryProcessor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ListFilters struct {
|
||||
Types []queryprocessor.Type
|
||||
}
|
||||
|
||||
type Test struct {
|
||||
QueryID uuid.UUID
|
||||
DocumentID uuid.UUID
|
||||
QueryVersion int32
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *repository.Queries
|
||||
}
|
||||
@@ -26,12 +11,3 @@ type Service struct {
|
||||
func New(db *repository.Queries) *Service {
|
||||
return &Service{db}
|
||||
}
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*queryprocessor.Query, error) {
|
||||
query, err := s.db.GetQuery(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return queryprocessor.ParseDBGetQuery(&query)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,16 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Test struct {
|
||||
QueryID uuid.UUID
|
||||
DocumentID uuid.UUID
|
||||
QueryVersion int32
|
||||
}
|
||||
|
||||
func (s *Service) Test(ctx context.Context, filters Test) (string, error) {
|
||||
// TODO
|
||||
// Sync doc - documentID
|
||||
|
||||
@@ -60,43 +60,3 @@ func ParseDBCollectorQuery(q *repository.GetCollectorQueriesRow) (*Query, error)
|
||||
RequiredQueryIDs: reqQueryIDs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ParseDBListQuery(q *repository.ListQueriesRow) (*Query, error) {
|
||||
reqQueryIDs := make([]uuid.UUID, len(q.Requiredids))
|
||||
for index, id := range q.Requiredids {
|
||||
reqQueryIDs[index] = database.MustToUUID(id)
|
||||
}
|
||||
|
||||
qType, err := ParseDBType(q.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
Version: q.Activeversion,
|
||||
Type: qType,
|
||||
RequiredQueryIDs: reqQueryIDs,
|
||||
Config: string(q.Config),
|
||||
}, nil
|
||||
}
|
||||
|
||||
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 := ParseDBType(q.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
Version: q.Activeversion,
|
||||
Type: qType,
|
||||
RequiredQueryIDs: reqQueryIDs,
|
||||
Config: string(q.Config),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user