]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
Adding typescript generation for API. Fixes #2824 (#2827)
[lemmy.git] / crates / api_common / src / community.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommunityId, LanguageId, PersonId},
4   source::site::Site,
5   ListingType,
6   SortType,
7 };
8 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
9 use serde::{Deserialize, Serialize};
10 use serde_with::skip_serializing_none;
11 #[cfg(feature = "full")]
12 use ts_rs::TS;
13
14 #[skip_serializing_none]
15 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
16 #[cfg_attr(feature = "full", derive(TS))]
17 #[cfg_attr(feature = "full", ts(export))]
18 pub struct GetCommunity {
19   pub id: Option<CommunityId>,
20   /// Example: star_trek , or star_trek@xyz.tld
21   pub name: Option<String>,
22   pub auth: Option<Sensitive<String>>,
23 }
24
25 #[skip_serializing_none]
26 #[derive(Debug, Serialize, Deserialize, Clone)]
27 #[cfg_attr(feature = "full", derive(TS))]
28 #[cfg_attr(feature = "full", ts(export))]
29 pub struct GetCommunityResponse {
30   pub community_view: CommunityView,
31   pub site: Option<Site>,
32   pub moderators: Vec<CommunityModeratorView>,
33   pub online: usize,
34   pub discussion_languages: Vec<LanguageId>,
35   /// Default language used for new posts if none is specified, generated based on community and
36   /// user languages.
37   pub default_post_language: Option<LanguageId>,
38 }
39
40 #[skip_serializing_none]
41 #[cfg_attr(feature = "full", derive(TS))]
42 #[cfg_attr(feature = "full", ts(export))]
43 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
44 pub struct CreateCommunity {
45   pub name: String,
46   pub title: String,
47   pub description: Option<String>,
48   pub icon: Option<String>,
49   pub banner: Option<String>,
50   pub nsfw: Option<bool>,
51   pub posting_restricted_to_mods: Option<bool>,
52   pub discussion_languages: Option<Vec<LanguageId>>,
53   pub auth: Sensitive<String>,
54 }
55
56 #[derive(Debug, Serialize, Deserialize, Clone)]
57 #[cfg_attr(feature = "full", derive(TS))]
58 #[cfg_attr(feature = "full", ts(export))]
59 pub struct CommunityResponse {
60   pub community_view: CommunityView,
61   pub discussion_languages: Vec<LanguageId>,
62 }
63
64 #[skip_serializing_none]
65 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
66 #[cfg_attr(feature = "full", derive(TS))]
67 #[cfg_attr(feature = "full", ts(export))]
68 pub struct ListCommunities {
69   pub type_: Option<ListingType>,
70   pub sort: Option<SortType>,
71   pub page: Option<i64>,
72   pub limit: Option<i64>,
73   pub auth: Option<Sensitive<String>>,
74 }
75
76 #[derive(Debug, Serialize, Deserialize, Clone)]
77 #[cfg_attr(feature = "full", derive(TS))]
78 #[cfg_attr(feature = "full", ts(export))]
79 pub struct ListCommunitiesResponse {
80   pub communities: Vec<CommunityView>,
81 }
82
83 #[skip_serializing_none]
84 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
85 #[cfg_attr(feature = "full", derive(TS))]
86 #[cfg_attr(feature = "full", ts(export))]
87 pub struct BanFromCommunity {
88   pub community_id: CommunityId,
89   pub person_id: PersonId,
90   pub ban: bool,
91   pub remove_data: Option<bool>,
92   pub reason: Option<String>,
93   pub expires: Option<i64>,
94   pub auth: Sensitive<String>,
95 }
96
97 #[derive(Debug, Serialize, Deserialize, Clone)]
98 #[cfg_attr(feature = "full", derive(TS))]
99 #[cfg_attr(feature = "full", ts(export))]
100 pub struct BanFromCommunityResponse {
101   pub person_view: PersonView,
102   pub banned: bool,
103 }
104
105 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
106 #[cfg_attr(feature = "full", derive(TS))]
107 #[cfg_attr(feature = "full", ts(export))]
108 pub struct AddModToCommunity {
109   pub community_id: CommunityId,
110   pub person_id: PersonId,
111   pub added: bool,
112   pub auth: Sensitive<String>,
113 }
114
115 #[derive(Debug, Serialize, Deserialize, Clone)]
116 #[cfg_attr(feature = "full", derive(TS))]
117 #[cfg_attr(feature = "full", ts(export))]
118 pub struct AddModToCommunityResponse {
119   pub moderators: Vec<CommunityModeratorView>,
120 }
121
122 #[skip_serializing_none]
123 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
124 #[cfg_attr(feature = "full", derive(TS))]
125 #[cfg_attr(feature = "full", ts(export))]
126 pub struct EditCommunity {
127   pub community_id: CommunityId,
128   pub title: Option<String>,
129   pub description: Option<String>,
130   pub icon: Option<String>,
131   pub banner: Option<String>,
132   pub nsfw: Option<bool>,
133   pub posting_restricted_to_mods: Option<bool>,
134   pub discussion_languages: Option<Vec<LanguageId>>,
135   pub auth: Sensitive<String>,
136 }
137
138 #[skip_serializing_none]
139 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
140 #[cfg_attr(feature = "full", derive(TS))]
141 #[cfg_attr(feature = "full", ts(export))]
142 pub struct HideCommunity {
143   pub community_id: CommunityId,
144   pub hidden: bool,
145   pub reason: Option<String>,
146   pub auth: Sensitive<String>,
147 }
148
149 #[skip_serializing_none]
150 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
151 #[cfg_attr(feature = "full", derive(TS))]
152 #[cfg_attr(feature = "full", ts(export))]
153 pub struct DeleteCommunity {
154   pub community_id: CommunityId,
155   pub deleted: bool,
156   pub auth: Sensitive<String>,
157 }
158
159 #[skip_serializing_none]
160 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
161 #[cfg_attr(feature = "full", derive(TS))]
162 #[cfg_attr(feature = "full", ts(export))]
163 pub struct RemoveCommunity {
164   pub community_id: CommunityId,
165   pub removed: bool,
166   pub reason: Option<String>,
167   pub expires: Option<i64>,
168   pub auth: Sensitive<String>,
169 }
170
171 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
172 #[cfg_attr(feature = "full", derive(TS))]
173 #[cfg_attr(feature = "full", ts(export))]
174 pub struct FollowCommunity {
175   pub community_id: CommunityId,
176   pub follow: bool,
177   pub auth: Sensitive<String>,
178 }
179
180 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
181 #[cfg_attr(feature = "full", derive(TS))]
182 #[cfg_attr(feature = "full", ts(export))]
183 pub struct BlockCommunity {
184   pub community_id: CommunityId,
185   pub block: bool,
186   pub auth: Sensitive<String>,
187 }
188
189 #[skip_serializing_none]
190 #[derive(Debug, Serialize, Deserialize, Clone)]
191 #[cfg_attr(feature = "full", derive(TS))]
192 #[cfg_attr(feature = "full", ts(export))]
193 pub struct BlockCommunityResponse {
194   pub community_view: CommunityView,
195   pub blocked: bool,
196 }
197
198 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
199 #[cfg_attr(feature = "full", derive(TS))]
200 #[cfg_attr(feature = "full", ts(export))]
201 pub struct TransferCommunity {
202   pub community_id: CommunityId,
203   pub person_id: PersonId,
204   pub auth: Sensitive<String>,
205 }