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