Skip to content

Commit

Permalink
Merge pull request #323 from abdullah1308/meshmodel-category-count
Browse files Browse the repository at this point in the history
Added counts to meshmodel categories
  • Loading branch information
leecalcote authored Jun 24, 2023
2 parents 403bdf4 + e755055 commit 437d6c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion models/meshmodel/core/v1alpha1/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func GetMeshModelRelationship(db *database.Handler, f RelationshipFilter) (r []R
if f.Greedy {
finder = finder.Where("relationship_definition_dbs.kind LIKE ?", "%"+f.Kind+"%")
} else {
finder = finder.Where("relationship_definition_dbs.kind = ?", "%"+f.Kind+"%")
finder = finder.Where("relationship_definition_dbs.kind = ?", f.Kind)
}
}
if f.SubType != "" {
Expand Down
17 changes: 15 additions & 2 deletions models/meshmodel/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,14 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
}
return m, count
}
func (rm *RegistryManager) GetCategories(db *database.Handler, f types.Filter) []v1alpha1.Category {
func (rm *RegistryManager) GetCategories(db *database.Handler, f types.Filter) ([]v1alpha1.Category, int64) {
var catdb []v1alpha1.CategoryDB
var cat []v1alpha1.Category
finder := rm.db.Model(&catdb)

// total count before pagination
var count int64

if mf, ok := f.(*v1alpha1.CategoryFilter); ok {
if mf.Name != "" {
if mf.Greedy {
Expand All @@ -269,18 +273,27 @@ func (rm *RegistryManager) GetCategories(db *database.Handler, f types.Filter) [
finder = finder.Order(mf.OrderOn)
}
}

finder.Count(&count)

if mf.Limit != 0 {
finder = finder.Limit(mf.Limit)
}
if mf.Offset != 0 {
finder = finder.Offset(mf.Offset)
}
}

if count == 0 {
finder.Count(&count)
}

_ = finder.Find(&catdb).Error
for _, c := range catdb {
cat = append(cat, c.GetCategory(db))
}
return cat

return cat, count
}
func (rm *RegistryManager) GetRegistrant(e Entity) Host {
eID := e.GetID()
Expand Down

0 comments on commit 437d6c8

Please sign in to comment.