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