]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
Use Url type for ap_id fields in database (fixes #1364)
[lemmy.git] / crates / db_schema / src / source / comment.rs
1 use crate::{
2   schema::{comment, comment_alias_1, comment_like, comment_saved},
3   source::post::Post,
4   Url,
5 };
6 use serde::Serialize;
7
8 // WITH RECURSIVE MyTree AS (
9 //     SELECT * FROM comment WHERE parent_id IS NULL
10 //     UNION ALL
11 //     SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
12 // )
13 // SELECT * FROM MyTree;
14
15 #[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
16 #[belongs_to(Post)]
17 #[table_name = "comment"]
18 pub struct Comment {
19   pub id: i32,
20   pub creator_id: i32,
21   pub post_id: i32,
22   pub parent_id: Option<i32>,
23   pub content: String,
24   pub removed: bool,
25   pub read: bool, // Whether the recipient has read the comment or not
26   pub published: chrono::NaiveDateTime,
27   pub updated: Option<chrono::NaiveDateTime>,
28   pub deleted: bool,
29   pub ap_id: Url,
30   pub local: bool,
31 }
32
33 #[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
34 #[belongs_to(Post)]
35 #[table_name = "comment_alias_1"]
36 pub struct CommentAlias1 {
37   pub id: i32,
38   pub creator_id: i32,
39   pub post_id: i32,
40   pub parent_id: Option<i32>,
41   pub content: String,
42   pub removed: bool,
43   pub read: bool, // Whether the recipient has read the comment or not
44   pub published: chrono::NaiveDateTime,
45   pub updated: Option<chrono::NaiveDateTime>,
46   pub deleted: bool,
47   pub ap_id: Url,
48   pub local: bool,
49 }
50
51 #[derive(Insertable, AsChangeset, Clone)]
52 #[table_name = "comment"]
53 pub struct CommentForm {
54   pub creator_id: i32,
55   pub post_id: i32,
56   pub parent_id: Option<i32>,
57   pub content: String,
58   pub removed: Option<bool>,
59   pub read: Option<bool>,
60   pub published: Option<chrono::NaiveDateTime>,
61   pub updated: Option<chrono::NaiveDateTime>,
62   pub deleted: Option<bool>,
63   pub ap_id: Option<Url>,
64   pub local: bool,
65 }
66
67 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
68 #[belongs_to(Comment)]
69 #[table_name = "comment_like"]
70 pub struct CommentLike {
71   pub id: i32,
72   pub user_id: i32,
73   pub comment_id: i32,
74   pub post_id: i32, // TODO this is redundant
75   pub score: i16,
76   pub published: chrono::NaiveDateTime,
77 }
78
79 #[derive(Insertable, AsChangeset, Clone)]
80 #[table_name = "comment_like"]
81 pub struct CommentLikeForm {
82   pub user_id: i32,
83   pub comment_id: i32,
84   pub post_id: i32, // TODO this is redundant
85   pub score: i16,
86 }
87
88 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
89 #[belongs_to(Comment)]
90 #[table_name = "comment_saved"]
91 pub struct CommentSaved {
92   pub id: i32,
93   pub comment_id: i32,
94   pub user_id: i32,
95   pub published: chrono::NaiveDateTime,
96 }
97
98 #[derive(Insertable, AsChangeset)]
99 #[table_name = "comment_saved"]
100 pub struct CommentSavedForm {
101   pub comment_id: i32,
102   pub user_id: i32,
103 }