]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / db_schema / src / source / post.rs
1 use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3 use typed_builder::TypedBuilder;
4
5 #[cfg(feature = "full")]
6 use crate::schema::{post, post_like, post_read, post_saved};
7
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))]
11 pub struct Post {
12   pub id: PostId,
13   pub name: String,
14   pub url: Option<DbUrl>,
15   pub body: Option<String>,
16   pub creator_id: PersonId,
17   pub community_id: CommunityId,
18   pub removed: bool,
19   pub locked: bool,
20   pub published: chrono::NaiveDateTime,
21   pub updated: Option<chrono::NaiveDateTime>,
22   pub deleted: bool,
23   pub nsfw: bool,
24   pub stickied: bool,
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>,
29   pub ap_id: DbUrl,
30   pub local: bool,
31   pub language_id: LanguageId,
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 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>,
61 }
62
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>,
85 }
86
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))]
91 pub struct PostLike {
92   pub id: i32,
93   pub post_id: PostId,
94   pub person_id: PersonId,
95   pub score: i16,
96   pub published: chrono::NaiveDateTime,
97 }
98
99 #[derive(Clone)]
100 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
101 #[cfg_attr(feature = "full", diesel(table_name = post_like))]
102 pub struct PostLikeForm {
103   pub post_id: PostId,
104   pub person_id: PersonId,
105   pub score: i16,
106 }
107
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 {
113   pub id: i32,
114   pub post_id: PostId,
115   pub person_id: PersonId,
116   pub published: chrono::NaiveDateTime,
117 }
118
119 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
120 #[cfg_attr(feature = "full", diesel(table_name = post_saved))]
121 pub struct PostSavedForm {
122   pub post_id: PostId,
123   pub person_id: PersonId,
124 }
125
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 {
131   pub id: i32,
132   pub post_id: PostId,
133   pub person_id: PersonId,
134   pub published: chrono::NaiveDateTime,
135 }
136
137 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
138 #[cfg_attr(feature = "full", diesel(table_name = post_read))]
139 pub struct PostReadForm {
140   pub post_id: PostId,
141   pub person_id: PersonId,
142 }