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>,
24 pub embed_title: Option<String>,
25 pub embed_description: Option<String>,
26 pub embed_video_url: Option<DbUrl>,
27 pub thumbnail_url: Option<DbUrl>,
30 pub language_id: LanguageId,
33 #[derive(Debug, Clone, TypedBuilder)]
34 #[builder(field_defaults(default))]
35 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
36 #[cfg_attr(feature = "full", diesel(table_name = post))]
37 pub struct PostInsertForm {
41 pub creator_id: PersonId,
43 pub community_id: CommunityId,
44 pub nsfw: Option<bool>,
45 pub url: Option<DbUrl>,
46 pub body: Option<String>,
47 pub removed: Option<bool>,
48 pub locked: Option<bool>,
49 pub updated: Option<chrono::NaiveDateTime>,
50 pub published: Option<chrono::NaiveDateTime>,
51 pub deleted: Option<bool>,
52 pub stickied: 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>,
62 #[derive(Debug, Clone, TypedBuilder)]
63 #[builder(field_defaults(default))]
64 #[cfg_attr(feature = "full", derive(AsChangeset))]
65 #[cfg_attr(feature = "full", diesel(table_name = post))]
66 pub struct PostUpdateForm {
67 pub name: Option<String>,
68 pub nsfw: Option<bool>,
69 pub url: Option<Option<DbUrl>>,
70 pub body: Option<Option<String>>,
71 pub removed: Option<bool>,
72 pub locked: Option<bool>,
73 pub published: Option<chrono::NaiveDateTime>,
74 pub updated: Option<Option<chrono::NaiveDateTime>>,
75 pub deleted: Option<bool>,
76 pub stickied: Option<bool>,
77 pub embed_title: Option<Option<String>>,
78 pub embed_description: Option<Option<String>>,
79 pub embed_video_url: Option<Option<DbUrl>>,
80 pub thumbnail_url: Option<Option<DbUrl>>,
81 pub ap_id: Option<DbUrl>,
82 pub local: Option<bool>,
83 pub language_id: Option<LanguageId>,
86 #[derive(PartialEq, Eq, Debug)]
87 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
88 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
89 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
93 pub person_id: PersonId,
95 pub published: chrono::NaiveDateTime,
99 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
100 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
101 pub struct PostLikeForm {
103 pub person_id: PersonId,
107 #[derive(PartialEq, Eq, Debug)]
108 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
109 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
110 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
111 pub struct PostSaved {
114 pub person_id: PersonId,
115 pub published: chrono::NaiveDateTime,
118 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
119 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
120 pub struct PostSavedForm {
122 pub person_id: PersonId,
125 #[derive(PartialEq, Eq, Debug)]
126 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
127 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
128 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
129 pub struct PostRead {
132 pub person_id: PersonId,
133 pub published: chrono::NaiveDateTime,
136 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
137 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
138 pub struct PostReadForm {
140 pub person_id: PersonId,