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