made the category hierarchy on Find Communities "live"

This commit is contained in:
2025-10-19 21:48:37 -06:00
parent 89da7e8456
commit 71da667361
3 changed files with 118 additions and 91 deletions
+28 -2
View File
@@ -11,6 +11,8 @@ package database
import (
"errors"
"slices"
"strings"
"sync"
)
@@ -19,8 +21,8 @@ type Category struct {
CatId int32 `db:"catid"`
Parent int32 `db:"parent"`
SymLink int32 `db:"symlink"`
HideDirectory int32 `db:"hide_dir"`
HideSearch int32 `db:"hide_search"`
HideDirectory bool `db:"hide_dir"`
HideSearch bool `db:"hide_search"`
Name string `db:"name"`
}
@@ -113,3 +115,27 @@ func AmGetCategoryHierarchy(catid int32) ([]*Category, error) {
}
return rc, nil
}
/* AmGetSubCategories returns a list of all subcategories of the given category ID.
* Parameters:
* catid - The parent category ID to use. May be -1 to return all "top level" categories.
* Returns:
* List of subcategories of this category.
* Standard Go error status.
*/
func AmGetSubCategories(catid int32) ([]*Category, error) {
err := loadCategories()
if err != nil {
return nil, err
}
rc := make([]*Category, 0)
for i, cat := range allCategories {
if catid == cat.Parent {
rc = append(rc, &(allCategories[i]))
}
}
slices.SortFunc(rc, func(a, b *Category) int {
return strings.Compare(a.Name, b.Name)
})
return rc, nil
}