]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
df3116ef3907c599eca986521c7ce0a31556bca7
[lemmy.git] / crates / db_schema / src / source / post.rs
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;
6
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))]
10 pub struct Post {
11   pub id: PostId,
12   pub name: String,
13   pub url: Option<DbUrl>,
14   pub body: Option<String>,
15   pub creator_id: PersonId,
16   pub community_id: CommunityId,
17   pub removed: bool,
18   pub locked: bool,
19   pub published: chrono::NaiveDateTime,
20   pub updated: Option<chrono::NaiveDateTime>,
21   pub deleted: bool,
22   pub nsfw: bool,
23   pub stickied: bool,
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>,
28   pub ap_id: DbUrl,
29   pub local: bool,
30   pub language_id: LanguageId,
31 }
32
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 {
38   #[builder(!default)]
39   pub name: String,
40   #[builder(!default)]
41   pub creator_id: PersonId,
42   #[builder(!default)]
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>,
60 }
61
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>,
84 }
85
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))]
90 pub struct PostLike {
91   pub id: i32,
92   pub post_id: PostId,
93   pub person_id: PersonId,
94   pub score: i16,
95   pub published: chrono::NaiveDateTime,
96 }
97
98 #[derive(Clone)]
99 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
100 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
101 pub struct PostLikeForm {
102   pub post_id: PostId,
103   pub person_id: PersonId,
104   pub score: i16,
105 }
106
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 {
112   pub id: i32,
113   pub post_id: PostId,
114   pub person_id: PersonId,
115   pub published: chrono::NaiveDateTime,
116 }
117
118 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
119 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
120 pub struct PostSavedForm {
121   pub post_id: PostId,
122   pub person_id: PersonId,
123 }
124
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 {
130   pub id: i32,
131   pub post_id: PostId,
132   pub person_id: PersonId,
133   pub published: chrono::NaiveDateTime,
134 }
135
136 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
137 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
138 pub struct PostReadForm {
139   pub post_id: PostId,
140   pub person_id: PersonId,
141 }