Skip to main content

dsc/api/
models.rs

1use serde::{Deserialize, Serialize};
2
3/// Response payload for site.json.
4#[derive(Debug, Deserialize)]
5pub struct SiteResponse {
6    pub site: SiteInfo,
7}
8
9/// Site metadata.
10#[derive(Debug, Deserialize)]
11pub struct SiteInfo {
12    pub title: String,
13}
14
15/// Response payload for about.json.
16#[derive(Debug, Deserialize)]
17pub struct AboutResponse {
18    pub about: AboutInfo,
19}
20
21/// About metadata.
22#[derive(Debug, Deserialize)]
23pub struct AboutInfo {
24    pub version: Option<String>,
25    pub installed_version: Option<String>,
26}
27
28/// Response payload for topic JSON.
29#[derive(Debug, Deserialize)]
30pub struct TopicResponse {
31    #[serde(default)]
32    pub title: Option<String>,
33    #[serde(default)]
34    pub slug: Option<String>,
35    pub post_stream: PostStream,
36}
37
38/// Topic post stream.
39#[derive(Debug, Deserialize, Default)]
40pub struct PostStream {
41    #[serde(default)]
42    pub posts: Vec<Post>,
43    /// Flat array of every post ID in the topic. Discourse includes this
44    /// on the first-page response only. Used to paginate the rest of the
45    /// thread via the batch-fetch endpoint.
46    #[serde(default)]
47    pub stream: Vec<u64>,
48}
49
50/// Topic post.
51#[derive(Debug, Deserialize)]
52pub struct Post {
53    pub id: u64,
54    #[serde(default)]
55    pub post_number: Option<u64>,
56    #[serde(default)]
57    pub username: Option<String>,
58    #[serde(default)]
59    pub raw: Option<String>,
60    #[serde(default)]
61    pub updated_at: Option<String>,
62    #[serde(default)]
63    pub created_at: Option<String>,
64}
65
66#[derive(Debug, Deserialize, Serialize)]
67pub struct CustomEmoji {
68    pub name: String,
69    pub url: String,
70}
71
72/// Response payload for category JSON.
73#[derive(Debug, Deserialize)]
74pub struct CategoryResponse {
75    #[serde(default)]
76    pub category: Option<CategoryInfo>,
77    pub topic_list: TopicList,
78}
79
80/// Category metadata.
81#[derive(Debug, Deserialize, Serialize, Clone)]
82pub struct CategoryInfo {
83    pub name: String,
84    pub slug: String,
85    #[serde(default)]
86    pub color: Option<String>,
87    #[serde(default)]
88    pub text_color: Option<String>,
89    pub id: Option<u64>,
90    #[serde(default)]
91    pub subcategory_list: Vec<CategoryInfo>,
92    #[serde(default)]
93    pub parent_category_id: Option<u64>,
94}
95
96/// Response payload for categories.json.
97#[derive(Debug, Deserialize)]
98pub struct CategoriesResponse {
99    pub category_list: CategoryList,
100}
101
102/// Category listing.
103#[derive(Debug, Deserialize)]
104pub struct CategoryList {
105    pub categories: Vec<CategoryInfo>,
106}
107
108/// Topic list for a category.
109#[derive(Debug, Deserialize)]
110pub struct TopicList {
111    pub topics: Vec<TopicSummary>,
112}
113
114/// Topic summary.
115#[derive(Debug, Deserialize, Serialize)]
116pub struct TopicSummary {
117    pub id: u64,
118    pub title: String,
119    pub slug: String,
120}
121
122/// Group summary.
123#[derive(Debug, Deserialize, Serialize, Clone)]
124pub struct GroupSummary {
125    pub id: u64,
126    pub name: String,
127    #[serde(default)]
128    pub full_name: Option<String>,
129}
130
131/// Response payload for groups.json.
132#[derive(Debug, Deserialize)]
133pub struct GroupsResponse {
134    pub groups: Vec<GroupSummary>,
135}
136
137#[derive(Debug, Deserialize, Serialize, Clone)]
138pub struct GroupMember {
139    pub id: u64,
140    pub username: String,
141    #[serde(default)]
142    pub name: Option<String>,
143}
144
145#[derive(Debug, Deserialize)]
146pub struct GroupMembersResponse {
147    pub members: Vec<GroupMember>,
148}
149
150/// Response payload for group detail.
151#[derive(Debug, Deserialize)]
152pub struct GroupDetailResponse {
153    pub group: GroupDetail,
154}
155
156/// Group details with settings used for deep-copy.
157#[derive(Debug, Deserialize, Serialize, Clone)]
158pub struct GroupDetail {
159    pub id: u64,
160    pub name: String,
161    #[serde(default)]
162    pub full_name: Option<String>,
163    #[serde(default)]
164    pub title: Option<String>,
165    #[serde(default)]
166    pub grant_trust_level: Option<u64>,
167    #[serde(default)]
168    pub visibility_level: Option<u64>,
169    #[serde(default)]
170    pub mentionable_level: Option<u64>,
171    #[serde(default)]
172    pub messageable_level: Option<u64>,
173    #[serde(default)]
174    pub default_notification_level: Option<u64>,
175    #[serde(default)]
176    pub members_visibility_level: Option<u64>,
177    #[serde(default)]
178    pub primary_group: Option<bool>,
179    #[serde(default)]
180    pub public_admission: Option<bool>,
181    #[serde(default)]
182    pub public_exit: Option<bool>,
183    #[serde(default)]
184    pub allow_membership_requests: Option<bool>,
185    #[serde(default)]
186    pub automatic_membership_email_domains: Option<String>,
187    #[serde(default)]
188    pub automatic_membership_retroactive: Option<bool>,
189    #[serde(default)]
190    pub membership_request_template: Option<String>,
191    #[serde(default)]
192    pub flair_icon: Option<String>,
193    #[serde(default)]
194    pub flair_upload_id: Option<u64>,
195    #[serde(default)]
196    pub flair_color: Option<String>,
197    #[serde(default)]
198    pub flair_background_color: Option<String>,
199    #[serde(default)]
200    pub bio_raw: Option<String>,
201}
202
203/// Response payload for creating a post/topic.
204#[derive(Debug, Deserialize)]
205pub struct CreatePostResponse {
206    pub id: u64,
207    pub topic_id: u64,
208}
209
210/// Response payload for creating a category.
211#[derive(Debug, Deserialize)]
212pub struct CreateCategoryResponse {
213    pub category: CreatedCategory,
214}
215
216/// Created category payload.
217#[derive(Debug, Deserialize)]
218pub struct CreatedCategory {
219    pub id: u64,
220}
221
222/// Response payload for creating a group.
223#[derive(Debug, Deserialize)]
224pub struct CreateGroupResponse {
225    pub group: CreatedGroup,
226}
227
228/// Created group payload.
229#[derive(Debug, Deserialize)]
230pub struct CreatedGroup {
231    pub id: u64,
232}