]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
add enable_federated_downvotes site option
[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, Default)]
89 #[cfg_attr(feature = "full", derive(AsChangeset))]
90 #[cfg_attr(feature = "full", diesel(table_name = post))]
91 pub struct PostUpdateForm {
92   pub name: Option<String>,
93   pub nsfw: Option<bool>,
94   pub url: Option<Option<DbUrl>>,
95   pub body: Option<Option<String>>,
96   pub removed: Option<bool>,
97   pub locked: Option<bool>,
98   pub published: Option<chrono::NaiveDateTime>,
99   pub updated: Option<Option<chrono::NaiveDateTime>>,
100   pub deleted: Option<bool>,
101   pub embed_title: Option<Option<String>>,
102   pub embed_description: Option<Option<String>>,
103   pub embed_video_url: Option<Option<DbUrl>>,
104   pub thumbnail_url: Option<Option<DbUrl>>,
105   pub ap_id: Option<DbUrl>,
106   pub local: Option<bool>,
107   pub language_id: Option<LanguageId>,
108   pub featured_community: Option<bool>,
109   pub featured_local: Option<bool>,
110 }
111
112 #[derive(PartialEq, Eq, Debug)]
113 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
114 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
115 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
116 pub struct PostLike {
117   pub id: i32,
118   pub post_id: PostId,
119   pub person_id: PersonId,
120   pub score: i16,
121   pub published: chrono::NaiveDateTime,
122 }
123
124 #[derive(Clone)]
125 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
126 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
127 pub struct PostLikeForm {
128   pub post_id: PostId,
129   pub person_id: PersonId,
130   pub score: i16,
131 }
132
133 #[derive(PartialEq, Eq, Debug)]
134 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
135 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
136 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
137 pub struct PostSaved {
138   pub id: i32,
139   pub post_id: PostId,
140   pub person_id: PersonId,
141   pub published: chrono::NaiveDateTime,
142 }
143
144 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
145 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
146 pub struct PostSavedForm {
147   pub post_id: PostId,
148   pub person_id: PersonId,
149 }
150
151 #[derive(PartialEq, Eq, Debug)]
152 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
153 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
154 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
155 pub struct PostRead {
156   pub id: i32,
157   pub post_id: PostId,
158   pub person_id: PersonId,
159   pub published: chrono::NaiveDateTime,
160 }
161
162 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
163 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
164 pub struct PostReadForm {
165   pub post_id: PostId,
166   pub person_id: PersonId,
167 }