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