Skip to content

Commit

Permalink
minor update:
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <[email protected]>
  • Loading branch information
MUzairS15 committed Aug 6, 2024
1 parent def3f00 commit a5da4b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
19 changes: 13 additions & 6 deletions models/meshmodel/registry/v1alpha2/relationship_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// In the future, we will add support to query using `selectors` (using CUE)
// TODO: Add support for Model
type RelationshipFilter struct {
Id string
Id string
Kind string
Greedy bool //when set to true - instead of an exact match, kind will be prefix matched
SubType string
Expand All @@ -23,6 +23,7 @@ type RelationshipFilter struct {
Sort string //asc or desc. Default behavior is asc
Limit int //If 0 or unspecified then all records are returned and limit is not used
Offset int
Status string
}

// Create the filter from map[string]interface{}
Expand All @@ -34,12 +35,12 @@ func (rf *RelationshipFilter) Create(m map[string]interface{}) {
}

func (rf *RelationshipFilter) GetById(db *database.Handler) (entity.Entity, error) {
r := &v1alpha2.RelationshipDefinition{}
err := db.First(r, "id = ?", rf.Id).Error
r := &v1alpha2.RelationshipDefinition{}
err := db.First(r, "id = ?", rf.Id).Error
if err != nil {
return nil, registry.ErrGetById(err, rf.Id)
}
return r, err
return r, err
}

func (relationshipFilter *RelationshipFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, error) {
Expand All @@ -49,8 +50,14 @@ func (relationshipFilter *RelationshipFilter) Get(db *database.Handler) ([]entit
Joins("JOIN model_dbs ON relationship_definition_dbs.model_id = model_dbs.id").
Joins("JOIN category_dbs ON model_dbs.category_id = category_dbs.id")

// TODO(@MUzairS15): Refactor this once Status is made a first class field in RelationshipFilter
finder = finder.Where("model_dbs.status = enabled")
// TODO(@MUzairS15): Refactor this once Status is made a first class field in RelationshipFilter
status := "enabled"

if relationshipFilter.Status != "" {
status = relationshipFilter.Status
}

finder = finder.Where("model_dbs.status = ?", status)

if relationshipFilter.Kind != "" {
if relationshipFilter.Greedy {
Expand Down
19 changes: 13 additions & 6 deletions models/meshmodel/registry/v1beta1/component_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type ComponentFilter struct {
Id string
Id string
Name string
APIVersion string
Greedy bool //when set to true - instead of an exact match, name will be matched as a substring
Expand All @@ -23,6 +23,7 @@ type ComponentFilter struct {
Limit int //If 0 or unspecified then all records are returned and limit is not used
Offset int
Annotations string //When this query parameter is "true", only components with the "isAnnotation" property set to true are returned. When this query parameter is "false", all components except those considered to be annotation components are returned. Any other value of the query parameter results in both annotations as well as non-annotation models being returned.
Status string
}

type componentDefinitionWithModel struct {
Expand All @@ -33,12 +34,12 @@ type componentDefinitionWithModel struct {
}

func (cf *ComponentFilter) GetById(db *database.Handler) (entity.Entity, error) {
c := &v1beta1.ComponentDefinition{}
err := db.First(c, "id = ?", cf.Id).Error
c := &v1beta1.ComponentDefinition{}
err := db.First(c, "id = ?", cf.Id).Error
if err != nil {
return nil, registry.ErrGetById(err, cf.Id)
}
return c, err
return c, err
}

// Create the filter from map[string]interface{}
Expand Down Expand Up @@ -69,8 +70,14 @@ func (componentFilter *ComponentFilter) Get(db *database.Handler) ([]entity.Enti
Joins("JOIN hosts ON hosts.id = model_dbs.host_id")
//

// TODO(@MUzairS15): Refactor this once Status is made a first class field in ComponentFilter
finder = finder.Where("model_dbs.status = enabled")
// TODO(@MUzairS15): Refactor this once Status is made a first class field in ComponentFilter
status := "enabled"

if componentFilter.Status != "" {
status = componentFilter.Status
}

finder = finder.Where("model_dbs.status = ?", status)

if componentFilter.Greedy {
if componentFilter.Name != "" && componentFilter.DisplayName != "" {
Expand Down
9 changes: 9 additions & 0 deletions models/meshmodel/registry/v1beta1/model_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, e
if mf.Offset != 0 {
finder = finder.Offset(mf.Offset)
}

status := "enabled"

if mf.Status != "" {
status = mf.Status
}

finder = finder.Where("model_dbs.status = ?", status)

if mf.Status != "" {
finder = finder.Where("model_dbs.status = ?", mf.Status)
}
Expand Down

0 comments on commit a5da4b0

Please sign in to comment.