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