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