]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
0b14b3f49407ddee2b49ad1c6a5349d2ed6d3ac8
[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 embed_title: Option<String>,
24   pub embed_description: Option<String>,
25   pub embed_video_url: Option<DbUrl>,
26   pub thumbnail_url: Option<DbUrl>,
27   pub ap_id: DbUrl,
28   pub local: bool,
29   pub language_id: LanguageId,
30   pub featured_community: bool,
31   pub featured_local: bool,
32 }
33
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 {
39   #[builder(!default)]
40   pub name: String,
41   #[builder(!default)]
42   pub creator_id: PersonId,
43   #[builder(!default)]
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>,
62 }
63
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>,
87 }
88
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))]
93 pub struct PostLike {
94   pub id: i32,
95   pub post_id: PostId,
96   pub person_id: PersonId,
97   pub score: i16,
98   pub published: chrono::NaiveDateTime,
99 }
100
101 #[derive(Clone)]
102 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
103 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
104 pub struct PostLikeForm {
105   pub post_id: PostId,
106   pub person_id: PersonId,
107   pub score: i16,
108 }
109
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 {
115   pub id: i32,
116   pub post_id: PostId,
117   pub person_id: PersonId,
118   pub published: chrono::NaiveDateTime,
119 }
120
121 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
122 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
123 pub struct PostSavedForm {
124   pub post_id: PostId,
125   pub person_id: PersonId,
126 }
127
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 {
133   pub id: i32,
134   pub post_id: PostId,
135   pub person_id: PersonId,
136   pub published: chrono::NaiveDateTime,
137 }
138
139 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
140 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
141 pub struct PostReadForm {
142   pub post_id: PostId,
143   pub person_id: PersonId,
144 }