]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
Derive default for api request structs, move type enums (#2245)
[lemmy.git] / crates / api_common / src / community.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommunityId, PersonId},
4   source::site::Site,
5   ListingType,
6   SortType,
7 };
8 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
9 use serde::{Deserialize, Serialize};
10
11 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
12 pub struct GetCommunity {
13   pub id: Option<CommunityId>,
14   /// Example: star_trek , or star_trek@xyz.tld
15   pub name: Option<String>,
16   pub auth: Option<Sensitive<String>>,
17 }
18
19 #[derive(Debug, Serialize, Deserialize, Clone)]
20 pub struct GetCommunityResponse {
21   pub community_view: CommunityView,
22   pub site: Option<Site>,
23   pub moderators: Vec<CommunityModeratorView>,
24   pub online: usize,
25 }
26
27 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
28 pub struct CreateCommunity {
29   pub name: String,
30   pub title: String,
31   pub description: Option<String>,
32   pub icon: Option<String>,
33   pub banner: Option<String>,
34   pub nsfw: Option<bool>,
35   pub posting_restricted_to_mods: Option<bool>,
36   pub auth: Sensitive<String>,
37 }
38
39 #[derive(Debug, Serialize, Deserialize, Clone)]
40 pub struct CommunityResponse {
41   pub community_view: CommunityView,
42 }
43
44 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
45 pub struct ListCommunities {
46   pub type_: Option<ListingType>,
47   pub sort: Option<SortType>,
48   pub page: Option<i64>,
49   pub limit: Option<i64>,
50   pub auth: Option<Sensitive<String>>,
51 }
52
53 #[derive(Debug, Serialize, Deserialize, Clone)]
54 pub struct ListCommunitiesResponse {
55   pub communities: Vec<CommunityView>,
56 }
57
58 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
59 pub struct BanFromCommunity {
60   pub community_id: CommunityId,
61   pub person_id: PersonId,
62   pub ban: bool,
63   pub remove_data: Option<bool>,
64   pub reason: Option<String>,
65   pub expires: Option<i64>,
66   pub auth: Sensitive<String>,
67 }
68
69 #[derive(Debug, Serialize, Deserialize, Clone)]
70 pub struct BanFromCommunityResponse {
71   pub person_view: PersonViewSafe,
72   pub banned: bool,
73 }
74
75 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
76 pub struct AddModToCommunity {
77   pub community_id: CommunityId,
78   pub person_id: PersonId,
79   pub added: bool,
80   pub auth: Sensitive<String>,
81 }
82
83 #[derive(Debug, Serialize, Deserialize, Clone)]
84 pub struct AddModToCommunityResponse {
85   pub moderators: Vec<CommunityModeratorView>,
86 }
87
88 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
89 pub struct EditCommunity {
90   pub community_id: CommunityId,
91   pub title: Option<String>,
92   pub description: Option<String>,
93   pub icon: Option<String>,
94   pub banner: Option<String>,
95   pub nsfw: Option<bool>,
96   pub posting_restricted_to_mods: Option<bool>,
97   pub auth: Sensitive<String>,
98 }
99
100 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
101 pub struct HideCommunity {
102   pub community_id: CommunityId,
103   pub hidden: bool,
104   pub reason: Option<String>,
105   pub auth: Sensitive<String>,
106 }
107
108 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
109 pub struct DeleteCommunity {
110   pub community_id: CommunityId,
111   pub deleted: bool,
112   pub auth: Sensitive<String>,
113 }
114
115 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
116 pub struct RemoveCommunity {
117   pub community_id: CommunityId,
118   pub removed: bool,
119   pub reason: Option<String>,
120   pub expires: Option<i64>,
121   pub auth: Sensitive<String>,
122 }
123
124 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
125 pub struct FollowCommunity {
126   pub community_id: CommunityId,
127   pub follow: bool,
128   pub auth: Sensitive<String>,
129 }
130
131 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
132 pub struct BlockCommunity {
133   pub community_id: CommunityId,
134   pub block: bool,
135   pub auth: Sensitive<String>,
136 }
137
138 #[derive(Debug, Serialize, Deserialize, Clone)]
139 pub struct BlockCommunityResponse {
140   pub community_view: CommunityView,
141   pub blocked: bool,
142 }
143
144 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
145 pub struct TransferCommunity {
146   pub community_id: CommunityId,
147   pub person_id: PersonId,
148   pub auth: Sensitive<String>,
149 }