]> Untitled Git - lemmy.git/blob - crates/api_common/src/community.rs
Adding shortname fetching for users and communities. Fixes #1662 (#1663)
[lemmy.git] / crates / api_common / src / community.rs
1 use lemmy_db_schema::{CommunityId, PersonId};
2 use lemmy_db_views_actor::{
3   community_follower_view::CommunityFollowerView,
4   community_moderator_view::CommunityModeratorView,
5   community_view::CommunityView,
6   person_view::PersonViewSafe,
7 };
8 use serde::{Deserialize, Serialize};
9
10 #[derive(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<String>,
16 }
17
18 #[derive(Serialize)]
19 pub struct GetCommunityResponse {
20   pub community_view: CommunityView,
21   pub moderators: Vec<CommunityModeratorView>,
22   pub online: usize,
23 }
24
25 #[derive(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: String,
34 }
35
36 #[derive(Serialize, Clone)]
37 pub struct CommunityResponse {
38   pub community_view: CommunityView,
39 }
40
41 #[derive(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<String>,
48 }
49
50 #[derive(Serialize, Debug)]
51 pub struct ListCommunitiesResponse {
52   pub communities: Vec<CommunityView>,
53 }
54
55 #[derive(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: String,
64 }
65
66 #[derive(Serialize, Clone)]
67 pub struct BanFromCommunityResponse {
68   pub person_view: PersonViewSafe,
69   pub banned: bool,
70 }
71
72 #[derive(Deserialize)]
73 pub struct AddModToCommunity {
74   pub community_id: CommunityId,
75   pub person_id: PersonId,
76   pub added: bool,
77   pub auth: String,
78 }
79
80 #[derive(Serialize, Clone)]
81 pub struct AddModToCommunityResponse {
82   pub moderators: Vec<CommunityModeratorView>,
83 }
84
85 #[derive(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: String,
94 }
95
96 #[derive(Deserialize)]
97 pub struct DeleteCommunity {
98   pub community_id: CommunityId,
99   pub deleted: bool,
100   pub auth: String,
101 }
102
103 #[derive(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: String,
110 }
111
112 #[derive(Deserialize)]
113 pub struct FollowCommunity {
114   pub community_id: CommunityId,
115   pub follow: bool,
116   pub auth: String,
117 }
118
119 #[derive(Deserialize)]
120 pub struct GetFollowedCommunities {
121   pub auth: String,
122 }
123
124 #[derive(Serialize)]
125 pub struct GetFollowedCommunitiesResponse {
126   pub communities: Vec<CommunityFollowerView>,
127 }
128
129 #[derive(Deserialize)]
130 pub struct TransferCommunity {
131   pub community_id: CommunityId,
132   pub person_id: PersonId,
133   pub auth: String,
134 }