Skip to content

Commit

Permalink
missing function 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 1483c4b commit 5d1230f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions models/meshmodel/registry/v1beta1/model_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {

Expand Down

0 comments on commit 5d1230f

Please sign in to comment.