1 use crate::newtypes::{CommentId, DbUrl, LanguageId, LtreeDef, PersonId, PostId};
2 use diesel_ltree::Ltree;
3 use serde::{Deserialize, Serialize};
4 use typed_builder::TypedBuilder;
6 #[cfg(feature = "full")]
7 use crate::schema::{comment, comment_like, comment_saved};
9 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
10 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
11 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
12 #[cfg_attr(feature = "full", diesel(table_name = comment))]
15 pub creator_id: PersonId,
19 pub published: chrono::NaiveDateTime,
20 pub updated: Option<chrono::NaiveDateTime>,
24 #[serde(with = "LtreeDef")]
26 pub distinguished: bool,
27 pub language_id: LanguageId,
30 #[derive(Debug, Clone, TypedBuilder)]
31 #[builder(field_defaults(default))]
32 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
33 #[cfg_attr(feature = "full", diesel(table_name = comment))]
34 pub struct CommentInsertForm {
36 pub creator_id: PersonId,
41 pub removed: Option<bool>,
42 pub published: Option<chrono::NaiveDateTime>,
43 pub updated: Option<chrono::NaiveDateTime>,
44 pub deleted: Option<bool>,
45 pub ap_id: Option<DbUrl>,
46 pub local: Option<bool>,
47 pub distinguished: Option<bool>,
48 pub language_id: Option<LanguageId>,
51 #[derive(Debug, Clone, TypedBuilder)]
52 #[builder(field_defaults(default))]
53 #[cfg_attr(feature = "full", derive(AsChangeset))]
54 #[cfg_attr(feature = "full", diesel(table_name = comment))]
55 pub struct CommentUpdateForm {
56 pub content: Option<String>,
57 pub removed: Option<bool>,
58 // Don't use a default naive_now here, because the create function does a lot of comment updates
59 pub updated: Option<Option<chrono::NaiveDateTime>>,
60 pub deleted: Option<bool>,
61 pub ap_id: Option<DbUrl>,
62 pub local: Option<bool>,
63 pub distinguished: Option<bool>,
64 pub language_id: Option<LanguageId>,
67 #[derive(PartialEq, Eq, Debug, Clone)]
68 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
69 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
70 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
71 pub struct CommentLike {
73 pub person_id: PersonId,
74 pub comment_id: CommentId,
75 pub post_id: PostId, // TODO this is redundant
77 pub published: chrono::NaiveDateTime,
81 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
82 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
83 pub struct CommentLikeForm {
84 pub person_id: PersonId,
85 pub comment_id: CommentId,
86 pub post_id: PostId, // TODO this is redundant
90 #[derive(PartialEq, Eq, Debug)]
91 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
92 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
93 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
94 pub struct CommentSaved {
96 pub comment_id: CommentId,
97 pub person_id: PersonId,
98 pub published: chrono::NaiveDateTime,
101 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
102 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
103 pub struct CommentSavedForm {
104 pub comment_id: CommentId,
105 pub person_id: PersonId,