1
0
Fork 0

Implemented #3, nested categories for Discourse

This commit is contained in:
マリウス 2023-01-10 19:37:07 -05:00
parent ba46179d2f
commit 3fabca859f
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 32 additions and 10 deletions

View File

@ -79,6 +79,10 @@ func (a *CategoryServiceHandler) List(
return nil, err
}
q := req.URL.Query()
q.Add("include_subcategories", "true")
req.URL.RawQuery = q.Encode()
response := new(LatestCategoriesResponse)
if err = a.client.Do(ctx, req, response); err != nil {
return nil, err

View File

@ -132,20 +132,38 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
return []forum.Forum{}, err
}
for _, cat := range cats.CategoryList.Categories {
models = append(models, forum.Forum{
ID: strconv.Itoa(cat.ID),
Name: cat.Name,
Info: cat.Description,
SysIDX: sys.ID,
})
}
models = sys.recurseForums(&cats.CategoryList.Categories, nil)
return models, nil
}
func (sys *System) recurseForums(cats *[]api.CategoryModel, parent *forum.Forum) []forum.Forum {
var models []forum.Forum
sys.logger.Debugf("recursing categories: %d\n", len(*cats))
for i := 0; i < len(*cats); i++ {
sys.logger.Debugf("adding category: %s\n", (*cats)[i].Name)
var name = (*cats)[i].Name
if parent != nil {
name = fmt.Sprintf("%s / %s", parent.Name, name)
}
f := forum.Forum{
ID: strconv.Itoa((*cats)[i].ID),
Name: name,
Info: (*cats)[i].Description,
SysIDX: sys.ID,
}
models = append(models, f)
models = append(models, sys.recurseForums(&(*cats)[i].SubcategoryList, &f)...)
}
return models
}
func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
var catSlug string = ""
var catID int = -1