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, 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>,
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 {
120 pub person_id: PersonId,
122 pub published: chrono::NaiveDateTime,
126 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
127 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
128 pub struct PostLikeForm {
130 pub person_id: PersonId,
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 {
141 pub person_id: PersonId,
142 pub published: chrono::NaiveDateTime,
145 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
146 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
147 pub struct PostSavedForm {
149 pub person_id: PersonId,
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 {
159 pub person_id: PersonId,
160 pub published: chrono::NaiveDateTime,
163 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
164 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
165 pub struct PostReadForm {
167 pub person_id: PersonId,