]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
Merge remote-tracking branch 'yerba/split-api-crate' into test_merge_api_crates_reorg
[lemmy.git] / crates / api_common / src / site.rs
1 use lemmy_db_schema::{CommunityId, PersonId};
2 use lemmy_db_views::{
3   comment_view::CommentView,
4   local_user_view::LocalUserSettingsView,
5   post_view::PostView,
6   site_view::SiteView,
7 };
8 use lemmy_db_views_actor::{community_view::CommunityView, person_view::PersonViewSafe};
9 use lemmy_db_views_moderator::{
10   mod_add_community_view::ModAddCommunityView,
11   mod_add_view::ModAddView,
12   mod_ban_from_community_view::ModBanFromCommunityView,
13   mod_ban_view::ModBanView,
14   mod_lock_post_view::ModLockPostView,
15   mod_remove_comment_view::ModRemoveCommentView,
16   mod_remove_community_view::ModRemoveCommunityView,
17   mod_remove_post_view::ModRemovePostView,
18   mod_sticky_post_view::ModStickyPostView,
19 };
20 use serde::{Deserialize, Serialize};
21 use url::Url;
22
23 #[derive(Deserialize, Debug)]
24 pub struct Search {
25   pub q: String,
26   pub type_: String,
27   pub community_id: Option<CommunityId>,
28   pub community_name: Option<String>,
29   pub sort: String,
30   pub page: Option<i64>,
31   pub limit: Option<i64>,
32   pub auth: Option<String>,
33 }
34
35 #[derive(Serialize, Debug)]
36 pub struct SearchResponse {
37   pub type_: String,
38   pub comments: Vec<CommentView>,
39   pub posts: Vec<PostView>,
40   pub communities: Vec<CommunityView>,
41   pub users: Vec<PersonViewSafe>,
42 }
43
44 #[derive(Deserialize)]
45 pub struct GetModlog {
46   pub mod_person_id: Option<PersonId>,
47   pub community_id: Option<CommunityId>,
48   pub page: Option<i64>,
49   pub limit: Option<i64>,
50 }
51
52 #[derive(Serialize)]
53 pub struct GetModlogResponse {
54   pub removed_posts: Vec<ModRemovePostView>,
55   pub locked_posts: Vec<ModLockPostView>,
56   pub stickied_posts: Vec<ModStickyPostView>,
57   pub removed_comments: Vec<ModRemoveCommentView>,
58   pub removed_communities: Vec<ModRemoveCommunityView>,
59   pub banned_from_community: Vec<ModBanFromCommunityView>,
60   pub banned: Vec<ModBanView>,
61   pub added_to_community: Vec<ModAddCommunityView>,
62   pub added: Vec<ModAddView>,
63 }
64
65 #[derive(Deserialize)]
66 pub struct CreateSite {
67   pub name: String,
68   pub description: Option<String>,
69   pub icon: Option<Url>,
70   pub banner: Option<Url>,
71   pub enable_downvotes: bool,
72   pub open_registration: bool,
73   pub enable_nsfw: bool,
74   pub auth: String,
75 }
76
77 #[derive(Deserialize)]
78 pub struct EditSite {
79   pub name: String,
80   pub description: Option<String>,
81   pub icon: Option<String>,
82   pub banner: Option<String>,
83   pub enable_downvotes: bool,
84   pub open_registration: bool,
85   pub enable_nsfw: bool,
86   pub auth: String,
87 }
88
89 #[derive(Deserialize)]
90 pub struct GetSite {
91   pub auth: Option<String>,
92 }
93
94 #[derive(Serialize, Clone)]
95 pub struct SiteResponse {
96   pub site_view: SiteView,
97 }
98
99 #[derive(Serialize)]
100 pub struct GetSiteResponse {
101   pub site_view: Option<SiteView>, // Because the site might not be set up yet
102   pub admins: Vec<PersonViewSafe>,
103   pub banned: Vec<PersonViewSafe>,
104   pub online: usize,
105   pub version: String,
106   pub my_user: Option<LocalUserSettingsView>,
107   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
108 }
109
110 #[derive(Deserialize)]
111 pub struct TransferSite {
112   pub person_id: PersonId,
113   pub auth: String,
114 }
115
116 #[derive(Deserialize)]
117 pub struct GetSiteConfig {
118   pub auth: String,
119 }
120
121 #[derive(Serialize)]
122 pub struct GetSiteConfigResponse {
123   pub config_hjson: String,
124 }
125
126 #[derive(Deserialize)]
127 pub struct SaveSiteConfig {
128   pub config_hjson: String,
129   pub auth: String,
130 }
131
132 #[derive(Serialize)]
133 pub struct FederatedInstances {
134   pub linked: Vec<String>,
135   pub allowed: Option<Vec<String>>,
136   pub blocked: Option<Vec<String>>,
137 }