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 typed_builder::TypedBuilder;
7 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
8 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
9 #[cfg_attr(feature = "full", diesel(table_name = post))]
13 pub url: Option<DbUrl>,
14 pub body: Option<String>,
15 pub creator_id: PersonId,
16 pub community_id: CommunityId,
19 pub published: chrono::NaiveDateTime,
20 pub updated: Option<chrono::NaiveDateTime>,
23 pub embed_title: Option<String>,
24 pub embed_description: Option<String>,
25 pub embed_video_url: Option<DbUrl>,
26 pub thumbnail_url: Option<DbUrl>,
29 pub language_id: LanguageId,
30 pub featured_community: bool,
31 pub featured_local: bool,
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 embed_title: Option<String>,
54 pub embed_description: Option<String>,
55 pub embed_video_url: Option<DbUrl>,
56 pub thumbnail_url: Option<DbUrl>,
57 pub ap_id: Option<DbUrl>,
58 pub local: Option<bool>,
59 pub language_id: Option<LanguageId>,
60 pub featured_community: Option<bool>,
61 pub featured_local: Option<bool>,
64 #[derive(Debug, Clone, TypedBuilder)]
65 #[builder(field_defaults(default))]
66 #[cfg_attr(feature = "full", derive(AsChangeset))]
67 #[cfg_attr(feature = "full", diesel(table_name = post))]
68 pub struct PostUpdateForm {
69 pub name: Option<String>,
70 pub nsfw: Option<bool>,
71 pub url: Option<Option<DbUrl>>,
72 pub body: Option<Option<String>>,
73 pub removed: Option<bool>,
74 pub locked: Option<bool>,
75 pub published: Option<chrono::NaiveDateTime>,
76 pub updated: Option<Option<chrono::NaiveDateTime>>,
77 pub deleted: 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>,
85 pub featured_community: Option<bool>,
86 pub featured_local: Option<bool>,
89 #[derive(PartialEq, Eq, Debug)]
90 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
91 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
92 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
96 pub person_id: PersonId,
98 pub published: chrono::NaiveDateTime,
102 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
103 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
104 pub struct PostLikeForm {
106 pub person_id: PersonId,
110 #[derive(PartialEq, Eq, Debug)]
111 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
112 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
113 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
114 pub struct PostSaved {
117 pub person_id: PersonId,
118 pub published: chrono::NaiveDateTime,
121 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
122 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
123 pub struct PostSavedForm {
125 pub person_id: PersonId,
128 #[derive(PartialEq, Eq, Debug)]
129 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
130 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
131 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
132 pub struct PostRead {
135 pub person_id: PersonId,
136 pub published: chrono::NaiveDateTime,
139 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
140 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
141 pub struct PostReadForm {
143 pub person_id: PersonId,