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