]> Untitled Git - lemmy.git/blob - crates/api_common/src/post.rs
Add support for Featured Posts (#2585)
[lemmy.git] / crates / api_common / src / post.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
4   ListingType,
5   PostFeatureType,
6   SortType,
7 };
8 use lemmy_db_views::structs::{PostReportView, PostView};
9 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
10 use serde::{Deserialize, Serialize};
11 use url::Url;
12
13 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
14 pub struct CreatePost {
15   pub name: String,
16   pub community_id: CommunityId,
17   pub url: Option<Url>,
18   pub body: Option<String>,
19   pub honeypot: Option<String>,
20   pub nsfw: Option<bool>,
21   pub language_id: Option<LanguageId>,
22   pub auth: Sensitive<String>,
23 }
24
25 #[derive(Debug, Serialize, Deserialize, Clone)]
26 pub struct PostResponse {
27   pub post_view: PostView,
28 }
29
30 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
31 pub struct GetPost {
32   pub id: Option<PostId>,
33   pub comment_id: Option<CommentId>,
34   pub auth: Option<Sensitive<String>>,
35 }
36
37 #[derive(Debug, Serialize, Deserialize, Clone)]
38 pub struct GetPostResponse {
39   pub post_view: PostView,
40   pub community_view: CommunityView,
41   pub moderators: Vec<CommunityModeratorView>,
42   pub online: usize,
43 }
44
45 #[derive(Serialize, Deserialize, Debug, Clone, Default)]
46 pub struct GetPosts {
47   pub type_: Option<ListingType>,
48   pub sort: Option<SortType>,
49   pub page: Option<i64>,
50   pub limit: Option<i64>,
51   pub community_id: Option<CommunityId>,
52   pub community_name: Option<String>,
53   pub saved_only: Option<bool>,
54   pub auth: Option<Sensitive<String>>,
55 }
56
57 #[derive(Serialize, Deserialize, Debug, Clone)]
58 pub struct GetPostsResponse {
59   pub posts: Vec<PostView>,
60 }
61
62 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
63 pub struct CreatePostLike {
64   pub post_id: PostId,
65   pub score: i16,
66   pub auth: Sensitive<String>,
67 }
68
69 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
70 pub struct EditPost {
71   pub post_id: PostId,
72   pub name: Option<String>,
73   pub url: Option<Url>,
74   pub body: Option<String>,
75   pub nsfw: Option<bool>,
76   pub language_id: Option<LanguageId>,
77   pub auth: Sensitive<String>,
78 }
79
80 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
81 pub struct DeletePost {
82   pub post_id: PostId,
83   pub deleted: bool,
84   pub auth: Sensitive<String>,
85 }
86
87 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
88 pub struct RemovePost {
89   pub post_id: PostId,
90   pub removed: bool,
91   pub reason: Option<String>,
92   pub auth: Sensitive<String>,
93 }
94
95 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
96 pub struct MarkPostAsRead {
97   pub post_id: PostId,
98   pub read: bool,
99   pub auth: Sensitive<String>,
100 }
101
102 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
103 pub struct LockPost {
104   pub post_id: PostId,
105   pub locked: bool,
106   pub auth: Sensitive<String>,
107 }
108
109 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
110 pub struct FeaturePost {
111   pub post_id: PostId,
112   pub featured: bool,
113   pub feature_type: PostFeatureType,
114   pub auth: Sensitive<String>,
115 }
116
117 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
118 pub struct SavePost {
119   pub post_id: PostId,
120   pub save: bool,
121   pub auth: Sensitive<String>,
122 }
123
124 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
125 pub struct CreatePostReport {
126   pub post_id: PostId,
127   pub reason: String,
128   pub auth: Sensitive<String>,
129 }
130
131 #[derive(Debug, Serialize, Deserialize, Clone)]
132 pub struct PostReportResponse {
133   pub post_report_view: PostReportView,
134 }
135
136 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
137 pub struct ResolvePostReport {
138   pub report_id: PostReportId,
139   pub resolved: bool,
140   pub auth: Sensitive<String>,
141 }
142
143 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
144 pub struct ListPostReports {
145   pub page: Option<i64>,
146   pub limit: Option<i64>,
147   /// Only shows the unresolved reports
148   pub unresolved_only: Option<bool>,
149   /// if no community is given, it returns reports for all communities moderated by the auth user
150   pub community_id: Option<CommunityId>,
151   pub auth: Sensitive<String>,
152 }
153
154 #[derive(Debug, Serialize, Deserialize, Clone)]
155 pub struct ListPostReportsResponse {
156   pub post_reports: Vec<PostReportView>,
157 }
158
159 #[derive(Debug, Serialize, Deserialize, Clone)]
160 pub struct GetSiteMetadata {
161   pub url: Url,
162 }
163
164 #[derive(Debug, Serialize, Deserialize, Clone)]
165 pub struct GetSiteMetadataResponse {
166   pub metadata: SiteMetadata,
167 }
168
169 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
170 pub struct SiteMetadata {
171   pub title: Option<String>,
172   pub description: Option<String>,
173   pub(crate) image: Option<DbUrl>,
174   pub embed_video_url: Option<DbUrl>,
175 }