1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00
neonmodem/system/discourse/api/categories.go

95 lines
3.8 KiB
Go
Raw Normal View History

package api
2022-12-30 23:57:03 -05:00
import (
"context"
"net/http"
2024-07-31 18:47:17 -04:00
"github.com/guregu/null"
2022-12-30 23:57:03 -05:00
)
const CategoriesBaseURL = "/categories"
type LatestCategoriesResponse struct {
CategoryList struct {
CanCreateCategory bool `json:"can_create_category"`
CanCreateTopic bool `json:"can_create_topic"`
Categories []CategoryModel `json:"categories"`
} `json:"category_list"`
}
type CategoryModel struct {
ID int `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
TextColor string `json:"text_color"`
Slug string `json:"slug"`
TopicCount int `json:"topic_count"`
PostCount int `json:"post_count"`
Position int `json:"position"`
2024-07-31 18:47:17 -04:00
Description null.String `json:"description",omitempty`
DescriptionText null.String `json:"description_text",omitempty`
DescriptionExcerpt null.String `json:"description_excerpt",omitempty`
TopicUrl null.String `json:"topic_url",omitempty`
2022-12-30 23:57:03 -05:00
ReadRestricted bool `json:"read_restricted"`
2024-07-31 18:47:17 -04:00
Permission null.Int `json:"permission",omitempty`
2022-12-30 23:57:03 -05:00
NotificationLevel int `json:"notification_level"`
CanEdit bool `json:"can_edit"`
2024-07-31 18:47:17 -04:00
TopicTemplate null.String `json:"topic_template",omitempty`
HasChildren null.Bool `json:"has_children",omitempty`
SortOrder null.String `json:"sort_order",omitempty`
SortAscending null.Bool `json:"sort_ascending",omitempty`
2022-12-30 23:57:03 -05:00
ShowSubcategoryList bool `json:"show_subcategory_list"`
NumFeaturedTopics int `json:"num_featured_topics"`
2024-07-31 18:47:17 -04:00
DefaultView null.String `json:"default_view",omitempty`
2022-12-30 23:57:03 -05:00
SubcategoryListStyle string `json:"subcategory_list_style"`
DefaultTopPeriod string `json:"default_top_period"`
DefaultListFilter string `json:"default_list_filter"`
MinimumRequiredTags int `json:"minimum_required_tags"`
NavigateToFirstPostAfterRead bool `json:"navigate_to_first_post_after_read"`
TopicsDay int `json:"topics_day"`
TopicsWeek int `json:"topics_week"`
TopicsMonth int `json:"topics_month"`
TopicsYear int `json:"topics_year"`
TopicsAllTime int `json:"topics_all_time"`
IsUncategorized bool `json:"is_uncategorized"`
2023-01-05 18:20:10 -05:00
SubcategoryIDs []int `json:"subcategory_ids"`
2022-12-30 23:57:03 -05:00
SubcategoryList []CategoryModel `json:"subcategory_list"`
2024-07-31 18:47:17 -04:00
UploadedLogo null.String `json:"uploaded_logo",omitempty`
UploadedLogoDark null.String `json:"uploaded_logo_dark",omitempty`
UploadedBackground null.String `json:"uploaded_background",omitempty`
2022-12-30 23:57:03 -05:00
}
type CategoriesService interface {
List(
ctx context.Context,
) (*LatestCategoriesResponse, error)
}
type CategoryServiceHandler struct {
client *Client
}
// List
func (a *CategoryServiceHandler) List(
ctx context.Context,
) (*LatestCategoriesResponse, error) {
uri := CategoriesBaseURL + ".json"
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("include_subcategories", "true")
req.URL.RawQuery = q.Encode()
2022-12-30 23:57:03 -05:00
response := new(LatestCategoriesResponse)
if err = a.client.Do(ctx, req, response); err != nil {
return nil, err
}
return response, nil
}