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