Skip to content

Commit

Permalink
fix: fetch styles from db w/signoff
Browse files Browse the repository at this point in the history
Signed-off-by: Jougan-0 <[email protected]>
  • Loading branch information
Jougan-0 committed Aug 19, 2024
1 parent 93c2018 commit d30a4c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
4 changes: 0 additions & 4 deletions models/meshmodel/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 4 additions & 38 deletions models/meshmodel/registry/v1beta1/model_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 != "" {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d30a4c7

Please sign in to comment.