1 use crate::newtypes::{CommentId, DbUrl, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
4 #[cfg(feature = "full")]
5 use crate::schema::{comment, comment_alias_1, comment_like, comment_saved};
7 // WITH RECURSIVE MyTree AS (
8 // SELECT * FROM comment WHERE parent_id IS NULL
10 // SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
12 // SELECT * FROM MyTree;
14 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
15 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
16 #[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
17 #[cfg_attr(feature = "full", table_name = "comment")]
20 pub creator_id: PersonId,
22 pub parent_id: Option<CommentId>,
25 pub read: bool, // Whether the recipient has read the comment or not
26 pub published: chrono::NaiveDateTime,
27 pub updated: Option<chrono::NaiveDateTime>,
33 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
34 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
35 #[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
36 #[cfg_attr(feature = "full", table_name = "comment_alias_1")]
37 pub struct CommentAlias1 {
39 pub creator_id: PersonId,
41 pub parent_id: Option<CommentId>,
44 pub read: bool, // Whether the recipient has read the comment or not
45 pub published: chrono::NaiveDateTime,
46 pub updated: Option<chrono::NaiveDateTime>,
52 #[derive(Clone, Default)]
53 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
54 #[cfg_attr(feature = "full", table_name = "comment")]
55 pub struct CommentForm {
56 pub creator_id: PersonId,
59 pub parent_id: Option<CommentId>,
60 pub removed: Option<bool>,
61 pub read: Option<bool>,
62 pub published: Option<chrono::NaiveDateTime>,
63 pub updated: Option<chrono::NaiveDateTime>,
64 pub deleted: Option<bool>,
65 pub ap_id: Option<DbUrl>,
66 pub local: Option<bool>,
69 #[derive(PartialEq, Debug, Clone)]
70 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
71 #[cfg_attr(feature = "full", belongs_to(Comment))]
72 #[cfg_attr(feature = "full", table_name = "comment_like")]
73 pub struct CommentLike {
75 pub person_id: PersonId,
76 pub comment_id: CommentId,
77 pub post_id: PostId, // TODO this is redundant
79 pub published: chrono::NaiveDateTime,
83 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
84 #[cfg_attr(feature = "full", 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
92 #[derive(PartialEq, Debug)]
93 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
94 #[cfg_attr(feature = "full", belongs_to(Comment))]
95 #[cfg_attr(feature = "full", table_name = "comment_saved")]
96 pub struct CommentSaved {
98 pub comment_id: CommentId,
99 pub person_id: PersonId,
100 pub published: chrono::NaiveDateTime,
103 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
104 #[cfg_attr(feature = "full", table_name = "comment_saved")]
105 pub struct CommentSavedForm {
106 pub comment_id: CommentId,
107 pub person_id: PersonId,