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