2 schema::{comment, comment_alias_1, comment_like, comment_saved},
6 use url::{ParseError, Url};
8 // WITH RECURSIVE MyTree AS (
9 // SELECT * FROM comment WHERE parent_id IS NULL
11 // SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
13 // SELECT * FROM MyTree;
15 #[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
17 #[table_name = "comment"]
22 pub parent_id: Option<i32>,
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, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
35 #[table_name = "comment_alias_1"]
36 pub struct CommentAlias1 {
40 pub parent_id: Option<i32>,
43 pub read: bool, // Whether the recipient has read the comment or not
44 pub published: chrono::NaiveDateTime,
45 pub updated: Option<chrono::NaiveDateTime>,
51 #[derive(Insertable, AsChangeset, Clone)]
52 #[table_name = "comment"]
53 pub struct CommentForm {
56 pub parent_id: Option<i32>,
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<String>,
68 pub fn get_ap_id(&self) -> Result<Url, ParseError> {
69 Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
73 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
74 #[belongs_to(Comment)]
75 #[table_name = "comment_like"]
76 pub struct CommentLike {
80 pub post_id: i32, // TODO this is redundant
82 pub published: chrono::NaiveDateTime,
85 #[derive(Insertable, AsChangeset, Clone)]
86 #[table_name = "comment_like"]
87 pub struct CommentLikeForm {
90 pub post_id: i32, // TODO this is redundant
94 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
95 #[belongs_to(Comment)]
96 #[table_name = "comment_saved"]
97 pub struct CommentSaved {
101 pub published: chrono::NaiveDateTime,
104 #[derive(Insertable, AsChangeset)]
105 #[table_name = "comment_saved"]
106 pub struct CommentSavedForm {