]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
a3054e4080650755181c3387c6469b573976ef50
[lemmy.git] / crates / db_schema / src / source / post.rs
1 use crate::newtypes::{CommunityId, DbUrl, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3
4 #[cfg(feature = "full")]
5 use crate::schema::{post, post_like, post_read, post_saved};
6
7 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
8 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
9 #[cfg_attr(feature = "full", 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_html: Option<String>,
27   pub thumbnail_url: Option<DbUrl>,
28   pub ap_id: DbUrl,
29   pub local: bool,
30 }
31
32 #[derive(Default)]
33 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
34 #[cfg_attr(feature = "full", table_name = "post")]
35 pub struct PostForm {
36   pub name: String,
37   pub creator_id: PersonId,
38   pub community_id: CommunityId,
39   pub nsfw: Option<bool>,
40   pub url: Option<DbUrl>,
41   pub body: Option<String>,
42   pub removed: Option<bool>,
43   pub locked: Option<bool>,
44   pub published: Option<chrono::NaiveDateTime>,
45   pub updated: Option<chrono::NaiveDateTime>,
46   pub deleted: Option<bool>,
47   pub stickied: Option<bool>,
48   pub embed_title: Option<String>,
49   pub embed_description: Option<String>,
50   pub embed_html: Option<String>,
51   pub thumbnail_url: Option<DbUrl>,
52   pub ap_id: Option<DbUrl>,
53   pub local: Option<bool>,
54 }
55
56 #[derive(PartialEq, Debug)]
57 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
58 #[cfg_attr(feature = "full", belongs_to(Post))]
59 #[cfg_attr(feature = "full", table_name = "post_like")]
60 pub struct PostLike {
61   pub id: i32,
62   pub post_id: PostId,
63   pub person_id: PersonId,
64   pub score: i16,
65   pub published: chrono::NaiveDateTime,
66 }
67
68 #[derive(Clone)]
69 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
70 #[cfg_attr(feature = "full", table_name = "post_like")]
71 pub struct PostLikeForm {
72   pub post_id: PostId,
73   pub person_id: PersonId,
74   pub score: i16,
75 }
76
77 #[derive(PartialEq, Debug)]
78 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
79 #[cfg_attr(feature = "full", belongs_to(Post))]
80 #[cfg_attr(feature = "full", table_name = "post_saved")]
81 pub struct PostSaved {
82   pub id: i32,
83   pub post_id: PostId,
84   pub person_id: PersonId,
85   pub published: chrono::NaiveDateTime,
86 }
87
88 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
89 #[cfg_attr(feature = "full", table_name = "post_saved")]
90 pub struct PostSavedForm {
91   pub post_id: PostId,
92   pub person_id: PersonId,
93 }
94
95 #[derive(PartialEq, Debug)]
96 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
97 #[cfg_attr(feature = "full", belongs_to(Post))]
98 #[cfg_attr(feature = "full", table_name = "post_read")]
99 pub struct PostRead {
100   pub id: i32,
101   pub post_id: PostId,
102   pub person_id: PersonId,
103   pub published: chrono::NaiveDateTime,
104 }
105
106 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
107 #[cfg_attr(feature = "full", table_name = "post_read")]
108 pub struct PostReadForm {
109   pub post_id: PostId,
110   pub person_id: PersonId,
111 }