]> Untitled Git - lemmy.git/blob - crates/api_common/src/post.rs
Don't drop error context when adding a message to errors (#1958)
[lemmy.git] / crates / api_common / src / post.rs
1 use lemmy_db_schema::newtypes::{CommunityId, PostId, PostReportId};
2 use lemmy_db_views::{
3   comment_view::CommentView,
4   post_report_view::PostReportView,
5   post_view::PostView,
6 };
7 use lemmy_db_views_actor::{
8   community_moderator_view::CommunityModeratorView,
9   community_view::CommunityView,
10 };
11 use lemmy_utils::{request::SiteMetadata, Sensitive};
12 use serde::{Deserialize, Serialize};
13 use url::Url;
14
15 #[derive(Serialize, Deserialize, Debug)]
16 pub struct CreatePost {
17   pub name: String,
18   pub community_id: CommunityId,
19   pub url: Option<Url>,
20   pub body: Option<String>,
21   pub honeypot: Option<String>,
22   pub nsfw: Option<bool>,
23   pub auth: Sensitive<String>,
24 }
25
26 #[derive(Debug, Serialize, Deserialize, Clone)]
27 pub struct PostResponse {
28   pub post_view: PostView,
29 }
30
31 #[derive(Debug, Serialize, Deserialize)]
32 pub struct GetPost {
33   pub id: PostId,
34   pub auth: Option<Sensitive<String>>,
35 }
36
37 #[derive(Debug, Serialize, Deserialize)]
38 pub struct GetPostResponse {
39   pub post_view: PostView,
40   pub community_view: CommunityView,
41   pub comments: Vec<CommentView>,
42   pub moderators: Vec<CommunityModeratorView>,
43   pub online: usize,
44 }
45
46 #[derive(Serialize, Deserialize, Debug)]
47 pub struct GetPosts {
48   pub type_: Option<String>,
49   pub sort: Option<String>,
50   pub page: Option<i64>,
51   pub limit: Option<i64>,
52   pub community_id: Option<CommunityId>,
53   pub community_name: Option<String>,
54   pub saved_only: Option<bool>,
55   pub auth: Option<Sensitive<String>>,
56 }
57
58 #[derive(Serialize, Deserialize, Debug)]
59 pub struct GetPostsResponse {
60   pub posts: Vec<PostView>,
61 }
62
63 #[derive(Debug, Serialize, Deserialize)]
64 pub struct CreatePostLike {
65   pub post_id: PostId,
66   pub score: i16,
67   pub auth: Sensitive<String>,
68 }
69
70 #[derive(Debug, Serialize, Deserialize)]
71 pub struct EditPost {
72   pub post_id: PostId,
73   pub name: Option<String>,
74   pub url: Option<Url>,
75   pub body: Option<String>,
76   pub nsfw: Option<bool>,
77   pub auth: Sensitive<String>,
78 }
79
80 #[derive(Debug, Serialize, Deserialize)]
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)]
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)]
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)]
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)]
110 pub struct StickyPost {
111   pub post_id: PostId,
112   pub stickied: bool,
113   pub auth: Sensitive<String>,
114 }
115
116 #[derive(Debug, Serialize, Deserialize)]
117 pub struct SavePost {
118   pub post_id: PostId,
119   pub save: bool,
120   pub auth: Sensitive<String>,
121 }
122
123 #[derive(Debug, Serialize, Deserialize)]
124 pub struct CreatePostReport {
125   pub post_id: PostId,
126   pub reason: String,
127   pub auth: Sensitive<String>,
128 }
129
130 #[derive(Debug, Serialize, Deserialize, Clone)]
131 pub struct PostReportResponse {
132   pub post_report_view: PostReportView,
133 }
134
135 #[derive(Debug, Serialize, Deserialize)]
136 pub struct ResolvePostReport {
137   pub report_id: PostReportId,
138   pub resolved: bool,
139   pub auth: Sensitive<String>,
140 }
141
142 #[derive(Debug, Serialize, Deserialize)]
143 pub struct ListPostReports {
144   pub page: Option<i64>,
145   pub limit: Option<i64>,
146   /// Only shows the unresolved reports
147   pub unresolved_only: Option<bool>,
148   /// if no community is given, it returns reports for all communities moderated by the auth user
149   pub community_id: Option<CommunityId>,
150   pub auth: Sensitive<String>,
151 }
152
153 #[derive(Debug, Serialize, Deserialize)]
154 pub struct ListPostReportsResponse {
155   pub post_reports: Vec<PostReportView>,
156 }
157
158 #[derive(Serialize, Deserialize, Debug)]
159 pub struct GetSiteMetadata {
160   pub url: Url,
161 }
162
163 #[derive(Serialize, Deserialize, Clone, Debug)]
164 pub struct GetSiteMetadataResponse {
165   pub metadata: SiteMetadata,
166 }