Skip to content

Commit

Permalink
Merge pull request #280 from Revolyssup/addCategoryFilter
Browse files Browse the repository at this point in the history
Add search filter in Meshmodel categories
  • Loading branch information
Revolyssup authored Mar 21, 2023
2 parents 0474e31 + 1aa6e5b commit 3091c1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions models/meshmodel/core/v1alpha1/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type CategoryDB struct {
type CategoryFilter struct {
Name string
OrderOn string
Greedy bool
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
Expand Down
6 changes: 5 additions & 1 deletion models/meshmodel/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ func (rm *RegistryManager) GetCategories(db *database.Handler, f types.Filter) [
finder := rm.db.Model(&catdb)
if mf, ok := f.(*v1alpha1.CategoryFilter); ok {
if mf.Name != "" {
finder = finder.Where("name = ?", mf.Name)
if mf.Greedy {
finder = finder.Where("name LIKE ?", mf.Name+"%")
} else {
finder = finder.Where("name = ?", mf.Name)
}
}
if mf.OrderOn != "" {
if mf.Sort == "desc" {
Expand Down

0 comments on commit 3091c1f

Please sign in to comment.