Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix: failed query templates with catalog id
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode authored and gitlawr committed Aug 15, 2023
1 parent 11d68af commit b59e15f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/template/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ var (
func (h Handler) CollectionGet(req CollectionGetRequest) (CollectionGetResponse, int, error) {
query := h.modelClient.Templates().Query()

if len(req.CatalogIDs) != 0 {
query.Where(template.CatalogIDIn(req.CatalogIDs...))
}

if queries, ok := req.Querying(queryFields); ok {
query.Where(queries)
}
Expand Down Expand Up @@ -122,6 +126,8 @@ func (h Handler) CollectionGet(req CollectionGetRequest) (CollectionGetResponse,
switch dm.Type {
case datamessage.EventCreate, datamessage.EventUpdate:
entities, err := query.Clone().
// Must extract catalog ID.
Select(template.FieldCatalogID).
Where(template.IDIn(dm.Data...)).
Unique(false).
All(stream)
Expand Down Expand Up @@ -172,6 +178,8 @@ func (h Handler) CollectionGet(req CollectionGetRequest) (CollectionGetResponse,
}

entities, err := query.
// Must extract catalog ID.
Select(template.FieldCatalogID).
Unique(false).
All(req.Context)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/template/basic_view.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package template

import (
"errors"
"fmt"

"github.com/hashicorp/go-getter"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/seal-io/seal/pkg/dao/model"
"github.com/seal-io/seal/pkg/dao/model/predicate"
"github.com/seal-io/seal/pkg/dao/model/template"
"github.com/seal-io/seal/pkg/dao/types/object"
"github.com/seal-io/seal/utils/validation"
)

Expand Down Expand Up @@ -68,12 +70,30 @@ type (
predicate.Template, template.OrderOption,
] `query:",inline"`

CatalogIDs []object.ID `query:"catalogID,omitempty"`

Stream *runtime.RequestUnidiStream
}

CollectionGetResponse = []*model.TemplateOutput
)

func (r *CollectionGetRequest) Validate() error {
if err := r.TemplateQueryInputs.Validate(); err != nil {
return err
}

if r.CatalogIDs != nil {
for i := range r.CatalogIDs {
if !r.CatalogIDs[i].Valid() {
return errors.New("invalid catalog id")
}
}
}

return nil
}

func (r *CollectionGetRequest) SetStream(stream runtime.RequestUnidiStream) {
r.Stream = &stream
}
Expand Down

0 comments on commit b59e15f

Please sign in to comment.