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")]
8 use typed_builder::TypedBuilder;
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))]
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.
28 /// Whether the post is locked.
30 pub published: chrono::NaiveDateTime,
31 pub updated: Option<chrono::NaiveDateTime>,
32 /// Whether the post is deleted.
34 /// Whether the post is NSFW.
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.
46 /// Whether the post is local.
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,
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 {
66 pub creator_id: PersonId,
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>,
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>,
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 {
119 pub person_id: PersonId,
121 pub published: chrono::NaiveDateTime,
125 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
126 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
127 pub struct PostLikeForm {
129 pub person_id: PersonId,
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 {
140 pub person_id: PersonId,
141 pub published: chrono::NaiveDateTime,
144 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
145 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
146 pub struct PostSavedForm {
148 pub person_id: PersonId,
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 {
158 pub person_id: PersonId,
159 pub published: chrono::NaiveDateTime,
162 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
163 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
164 pub struct PostReadForm {
166 pub person_id: PersonId,