1 use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3 use typed_builder::TypedBuilder;
5 #[cfg(feature = "full")]
6 use crate::schema::{post, post_like, post_read, post_saved};
8 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
9 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
10 #[cfg_attr(feature = "full", diesel(table_name = post))]
14 pub url: Option<DbUrl>,
15 pub body: Option<String>,
16 pub creator_id: PersonId,
17 pub community_id: CommunityId,
20 pub published: chrono::NaiveDateTime,
21 pub updated: Option<chrono::NaiveDateTime>,
25 pub embed_title: Option<String>,
26 pub embed_description: Option<String>,
27 pub embed_video_url: Option<DbUrl>,
28 pub thumbnail_url: Option<DbUrl>,
31 pub language_id: LanguageId,
34 #[derive(Debug, Clone, TypedBuilder)]
35 #[builder(field_defaults(default))]
36 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
37 #[cfg_attr(feature = "full", diesel(table_name = post))]
38 pub struct PostInsertForm {
42 pub creator_id: PersonId,
44 pub community_id: CommunityId,
45 pub nsfw: Option<bool>,
46 pub url: Option<DbUrl>,
47 pub body: Option<String>,
48 pub removed: Option<bool>,
49 pub locked: Option<bool>,
50 pub updated: Option<chrono::NaiveDateTime>,
51 pub published: Option<chrono::NaiveDateTime>,
52 pub deleted: Option<bool>,
53 pub stickied: Option<bool>,
54 pub embed_title: Option<String>,
55 pub embed_description: Option<String>,
56 pub embed_video_url: Option<DbUrl>,
57 pub thumbnail_url: Option<DbUrl>,
58 pub ap_id: Option<DbUrl>,
59 pub local: Option<bool>,
60 pub language_id: Option<LanguageId>,
63 #[derive(Debug, Clone, TypedBuilder)]
64 #[builder(field_defaults(default))]
65 #[cfg_attr(feature = "full", derive(AsChangeset))]
66 #[cfg_attr(feature = "full", diesel(table_name = post))]
67 pub struct PostUpdateForm {
68 pub name: Option<String>,
69 pub nsfw: Option<bool>,
70 pub url: Option<Option<DbUrl>>,
71 pub body: Option<Option<String>>,
72 pub removed: Option<bool>,
73 pub locked: Option<bool>,
74 pub published: Option<chrono::NaiveDateTime>,
75 pub updated: Option<Option<chrono::NaiveDateTime>>,
76 pub deleted: Option<bool>,
77 pub stickied: Option<bool>,
78 pub embed_title: Option<Option<String>>,
79 pub embed_description: Option<Option<String>>,
80 pub embed_video_url: Option<Option<DbUrl>>,
81 pub thumbnail_url: Option<Option<DbUrl>>,
82 pub ap_id: Option<DbUrl>,
83 pub local: Option<bool>,
84 pub language_id: Option<LanguageId>,
87 #[derive(PartialEq, Eq, Debug)]
88 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
89 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
90 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
94 pub person_id: PersonId,
96 pub published: chrono::NaiveDateTime,
100 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
101 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
102 pub struct PostLikeForm {
104 pub person_id: PersonId,
108 #[derive(PartialEq, Eq, Debug)]
109 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
110 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
111 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
112 pub struct PostSaved {
115 pub person_id: PersonId,
116 pub published: chrono::NaiveDateTime,
119 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
120 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
121 pub struct PostSavedForm {
123 pub person_id: PersonId,
126 #[derive(PartialEq, Eq, Debug)]
127 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
128 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
129 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
130 pub struct PostRead {
133 pub person_id: PersonId,
134 pub published: chrono::NaiveDateTime,
137 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
138 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
139 pub struct PostReadForm {
141 pub person_id: PersonId,