]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
Split activity table into sent and received parts (fixes #3103) (#3583)
[lemmy.git] / crates / db_schema / src / source / post.rs
1 use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId};
2 #[cfg(feature = "full")]
3 use crate::schema::{post, post_like, post_read, post_saved};
4 use serde::{Deserialize, Serialize};
5 use serde_with::skip_serializing_none;
6 #[cfg(feature = "full")]
7 use ts_rs::TS;
8 use typed_builder::TypedBuilder;
9
10 #[skip_serializing_none]
11 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
12 #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))]
13 #[cfg_attr(feature = "full", diesel(table_name = post))]
14 #[cfg_attr(feature = "full", ts(export))]
15 /// A post.
16 pub struct Post {
17   pub id: PostId,
18   pub name: String,
19   #[cfg_attr(feature = "full", ts(type = "string"))]
20   /// An optional link / url for the post.
21   pub url: Option<DbUrl>,
22   /// An optional post body, in markdown.
23   pub body: Option<String>,
24   pub creator_id: PersonId,
25   pub community_id: CommunityId,
26   /// Whether the post is removed.
27   pub removed: bool,
28   /// Whether the post is locked.
29   pub locked: bool,
30   pub published: chrono::NaiveDateTime,
31   pub updated: Option<chrono::NaiveDateTime>,
32   /// Whether the post is deleted.
33   pub deleted: bool,
34   /// Whether the post is NSFW.
35   pub nsfw: bool,
36   /// A title for the link.
37   pub embed_title: Option<String>,
38   /// A description for the link.
39   pub embed_description: Option<String>,
40   #[cfg_attr(feature = "full", ts(type = "string"))]
41   /// A thumbnail picture url.
42   pub thumbnail_url: Option<DbUrl>,
43   #[cfg_attr(feature = "full", ts(type = "string"))]
44   /// The federated activity id / ap_id.
45   pub ap_id: DbUrl,
46   /// Whether the post is local.
47   pub local: bool,
48   #[cfg_attr(feature = "full", ts(type = "string"))]
49   /// A video url for the link.
50   pub embed_video_url: Option<DbUrl>,
51   pub language_id: LanguageId,
52   /// Whether the post is featured to its community.
53   pub featured_community: bool,
54   /// Whether the post is featured to its site.
55   pub featured_local: bool,
56 }
57
58 #[derive(Debug, Clone, TypedBuilder)]
59 #[builder(field_defaults(default))]
60 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
61 #[cfg_attr(feature = "full", diesel(table_name = post))]
62 pub struct PostInsertForm {
63   #[builder(!default)]
64   pub name: String,
65   #[builder(!default)]
66   pub creator_id: PersonId,
67   #[builder(!default)]
68   pub community_id: CommunityId,
69   pub nsfw: Option<bool>,
70   pub url: Option<DbUrl>,
71   pub body: Option<String>,
72   pub removed: Option<bool>,
73   pub locked: Option<bool>,
74   pub updated: Option<chrono::NaiveDateTime>,
75   pub published: Option<chrono::NaiveDateTime>,
76   pub deleted: Option<bool>,
77   pub embed_title: Option<String>,
78   pub embed_description: Option<String>,
79   pub embed_video_url: Option<DbUrl>,
80   pub thumbnail_url: Option<DbUrl>,
81   pub ap_id: Option<DbUrl>,
82   pub local: Option<bool>,
83   pub language_id: Option<LanguageId>,
84   pub featured_community: Option<bool>,
85   pub featured_local: Option<bool>,
86 }
87
88 #[derive(Debug, Clone, TypedBuilder)]
89 #[builder(field_defaults(default))]
90 #[cfg_attr(feature = "full", derive(AsChangeset))]
91 #[cfg_attr(feature = "full", diesel(table_name = post))]
92 pub struct PostUpdateForm {
93   pub name: Option<String>,
94   pub nsfw: Option<bool>,
95   pub url: Option<Option<DbUrl>>,
96   pub body: Option<Option<String>>,
97   pub removed: Option<bool>,
98   pub locked: Option<bool>,
99   pub published: Option<chrono::NaiveDateTime>,
100   pub updated: Option<Option<chrono::NaiveDateTime>>,
101   pub deleted: Option<bool>,
102   pub embed_title: Option<Option<String>>,
103   pub embed_description: Option<Option<String>>,
104   pub embed_video_url: Option<Option<DbUrl>>,
105   pub thumbnail_url: Option<Option<DbUrl>>,
106   pub ap_id: Option<DbUrl>,
107   pub local: Option<bool>,
108   pub language_id: Option<LanguageId>,
109   pub featured_community: Option<bool>,
110   pub featured_local: Option<bool>,
111 }
112
113 #[derive(PartialEq, Eq, Debug)]
114 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
115 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
116 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
117 pub struct PostLike {
118   pub id: i32,
119   pub post_id: PostId,
120   pub person_id: PersonId,
121   pub score: i16,
122   pub published: chrono::NaiveDateTime,
123 }
124
125 #[derive(Clone)]
126 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
127 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
128 pub struct PostLikeForm {
129   pub post_id: PostId,
130   pub person_id: PersonId,
131   pub score: i16,
132 }
133
134 #[derive(PartialEq, Eq, Debug)]
135 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
136 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
137 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
138 pub struct PostSaved {
139   pub id: i32,
140   pub post_id: PostId,
141   pub person_id: PersonId,
142   pub published: chrono::NaiveDateTime,
143 }
144
145 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
146 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
147 pub struct PostSavedForm {
148   pub post_id: PostId,
149   pub person_id: PersonId,
150 }
151
152 #[derive(PartialEq, Eq, Debug)]
153 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
154 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
155 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
156 pub struct PostRead {
157   pub id: i32,
158   pub post_id: PostId,
159   pub person_id: PersonId,
160   pub published: chrono::NaiveDateTime,
161 }
162
163 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
164 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
165 pub struct PostReadForm {
166   pub post_id: PostId,
167   pub person_id: PersonId,
168 }