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