From d30a4c76151159d0c6618b5df3553f6abb5c0524 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 19 Aug 2024 13:45:52 +0530 Subject: [PATCH 1/3] fix: fetch styles from db w/signoff Signed-off-by: Jougan-0 --- models/meshmodel/registry/registry.go | 4 -- .../registry/v1beta1/model_filter.go | 42 ++----------------- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/models/meshmodel/registry/registry.go b/models/meshmodel/registry/registry.go index cc9d1c1b..e934df61 100644 --- a/models/meshmodel/registry/registry.go +++ b/models/meshmodel/registry/registry.go @@ -197,10 +197,6 @@ func (rm *RegistryManager) GetEntities(f entity.Filter) ([]entity.Entity, int64, return f.Get(rm.db) } -func (rm *RegistryManager) GetEntityById(f entity.Filter) (entity.Entity, error) { - return f.GetById(rm.db) -} - func HostnameToPascalCase(input string) string { parts := strings.Split(input, ".") caser := cases.Title(language.English) diff --git a/models/meshmodel/registry/v1beta1/model_filter.go b/models/meshmodel/registry/v1beta1/model_filter.go index 1819f1d2..9a806dc3 100644 --- a/models/meshmodel/registry/v1beta1/model_filter.go +++ b/models/meshmodel/registry/v1beta1/model_filter.go @@ -3,7 +3,6 @@ package v1beta1 import ( "github.com/layer5io/meshkit/database" "github.com/layer5io/meshkit/models/meshmodel/entity" - "github.com/layer5io/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" "github.com/meshery/schemas/models/v1beta1/component" "github.com/meshery/schemas/models/v1beta1/model" @@ -50,42 +49,6 @@ func countUniqueModels(models []model.ModelDefinition) int { return len(set) } -func (mf *ModelFilter) GetById(db *database.Handler) (entity.Entity, error) { - m := &model.ModelDefinition{} - - // Retrieve the model by ID - err := db.First(m, "id = ?", mf.Id).Error - if err != nil { - return nil, registry.ErrGetById(err, mf.Id) - } - - // Include components if requested - if mf.Components { - var components []component.ComponentDefinition - componentFinder := db.Model(&component.ComponentDefinition{}). - Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version"). - Where("component_definition_dbs.model_id = ?", m.Id) - if err := componentFinder.Scan(&components).Error; err != nil { - return nil, err - } - m.Components = components - } - - // Include relationships if requested - if mf.Relationships { - var relationships []relationship.RelationshipDefinition - relationshipFinder := db.Model(&relationship.RelationshipDefinition{}). - Select("relationship_definition_dbs.*"). - Where("relationship_definition_dbs.model_id = ?", m.Id) - if err := relationshipFinder.Scan(&relationships).Error; err != nil { - return nil, err - } - m.Relationships = relationships - } - - return m, nil -} - func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, error) { var modelWithCategories []model.ModelDefinition @@ -102,6 +65,9 @@ func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, e var includeComponents, includeRelationships bool if mf.Greedy { + if mf.Id != "" { + finder = finder.First("model_dbs.id = ?", mf.Id) + } if mf.Name != "" && mf.DisplayName != "" { finder = finder.Where("model_dbs.name LIKE ? OR model_dbs.display_name LIKE ?", "%"+mf.Name+"%", "%"+mf.DisplayName+"%") } else if mf.Name != "" { @@ -180,7 +146,7 @@ func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, e if includeComponents { var components []component.ComponentDefinition finder := db.Model(&component.ComponentDefinition{}). - Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version"). + Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version,component_definition_dbs.styles"). Where("component_definition_dbs.model_id = ?", _modelDB.Id) if err := finder.Scan(&components).Error; err != nil { return nil, 0, 0, err From 1483c4b306ee7462d3c5528bafe4e4cf4492e1e4 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 19 Aug 2024 13:47:57 +0530 Subject: [PATCH 2/3] fix liniting w/signoff Signed-off-by: Jougan-0 --- go.mod | 2 -- go.sum | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b914a6d2..d778a3fe 100644 --- a/go.mod +++ b/go.mod @@ -260,5 +260,3 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) - -replace github.com/meshery/schemas => ../schemas diff --git a/go.sum b/go.sum index 58dff424..59233ba0 100644 --- a/go.sum +++ b/go.sum @@ -608,6 +608,8 @@ github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/meshery/kompose v1.0.1 h1:lg8B/pkLh6762jeFsQATD8UJZZwXZf/aviC3/dzw78A= github.com/meshery/kompose v1.0.1/go.mod h1:TWhWTEMbJBUzENf4JTEtBmZRFm/r8n0nS6v4/nSD2vA= +github.com/meshery/schemas v0.7.19 h1:HS+PCZ3ZXbs7cv0JSUNW3kYnbypt3WqZjQ7fMQPy8uo= +github.com/meshery/schemas v0.7.19/go.mod h1:UfiO+zm92yLkaJP0aroNwVnjuozoh793AWDXrKDYmT0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= From 5d1230f96d588d92dcb403b224bca523ea974124 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 19 Aug 2024 17:32:37 +0530 Subject: [PATCH 3/3] missing function w/signoff Signed-off-by: Jougan-0 --- .../registry/v1beta1/model_filter.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/models/meshmodel/registry/v1beta1/model_filter.go b/models/meshmodel/registry/v1beta1/model_filter.go index 9a806dc3..86971485 100644 --- a/models/meshmodel/registry/v1beta1/model_filter.go +++ b/models/meshmodel/registry/v1beta1/model_filter.go @@ -3,6 +3,7 @@ package v1beta1 import ( "github.com/layer5io/meshkit/database" "github.com/layer5io/meshkit/models/meshmodel/entity" + "github.com/layer5io/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" "github.com/meshery/schemas/models/v1beta1/component" "github.com/meshery/schemas/models/v1beta1/model" @@ -48,6 +49,41 @@ func countUniqueModels(models []model.ModelDefinition) int { } return len(set) } +func (mf *ModelFilter) GetById(db *database.Handler) (entity.Entity, error) { + m := &model.ModelDefinition{} + + // Retrieve the model by ID + err := db.First(m, "id = ?", mf.Id).Error + if err != nil { + return nil, registry.ErrGetById(err, mf.Id) + } + + // Include components if requested + if mf.Components { + var components []component.ComponentDefinition + componentFinder := db.Model(&component.ComponentDefinition{}). + Select("component_definition_dbs.id, component_definition_dbs.component, component_definition_dbs.display_name, component_definition_dbs.metadata, component_definition_dbs.schema_version, component_definition_dbs.version"). + Where("component_definition_dbs.model_id = ?", m.Id) + if err := componentFinder.Scan(&components).Error; err != nil { + return nil, err + } + m.Components = components + } + + // Include relationships if requested + if mf.Relationships { + var relationships []relationship.RelationshipDefinition + relationshipFinder := db.Model(&relationship.RelationshipDefinition{}). + Select("relationship_definition_dbs.*"). + Where("relationship_definition_dbs.model_id = ?", m.Id) + if err := relationshipFinder.Scan(&relationships).Error; err != nil { + return nil, err + } + m.Relationships = relationships + } + + return m, nil +} func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, error) {