]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/post.rs
Tag posts and comments with language (fixes #440) (#2269)
[lemmy.git] / crates / db_schema / src / source / post.rs
1 use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3
4 #[cfg(feature = "full")]
5 use crate::schema::{post, post_like, post_read, post_saved};
6
7 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
8 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
9 #[cfg_attr(feature = "full", table_name = "post")]
10 pub struct Post {
11   pub id: PostId,
12   pub name: String,
13   pub url: Option<DbUrl>,
14   pub body: Option<String>,
15   pub creator_id: PersonId,
16   pub community_id: CommunityId,
17   pub removed: bool,
18   pub locked: bool,
19   pub published: chrono::NaiveDateTime,
20   pub updated: Option<chrono::NaiveDateTime>,
21   pub deleted: bool,
22   pub nsfw: bool,
23   pub stickied: bool,
24   pub embed_title: Option<String>,
25   pub embed_description: Option<String>,
26   pub embed_video_url: Option<DbUrl>,
27   pub thumbnail_url: Option<DbUrl>,
28   pub ap_id: DbUrl,
29   pub local: bool,
30   pub language_id: LanguageId,
31 }
32
33 #[derive(Default)]
34 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
35 #[cfg_attr(feature = "full", table_name = "post")]
36 pub struct PostForm {
37   pub name: String,
38   pub creator_id: PersonId,
39   pub community_id: CommunityId,
40   pub nsfw: Option<bool>,
41   pub url: Option<Option<DbUrl>>,
42   pub body: Option<Option<String>>,
43   pub removed: Option<bool>,
44   pub locked: Option<bool>,
45   pub published: Option<chrono::NaiveDateTime>,
46   pub updated: Option<chrono::NaiveDateTime>,
47   pub deleted: Option<bool>,
48   pub stickied: Option<bool>,
49   pub embed_title: Option<Option<String>>,
50   pub embed_description: Option<Option<String>>,
51   pub embed_video_url: Option<Option<DbUrl>>,
52   pub thumbnail_url: Option<Option<DbUrl>>,
53   pub ap_id: Option<DbUrl>,
54   pub local: Option<bool>,
55   pub language_id: Option<LanguageId>,
56 }
57
58 #[derive(PartialEq, Debug)]
59 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
60 #[cfg_attr(feature = "full", belongs_to(Post))]
61 #[cfg_attr(feature = "full", table_name = "post_like")]
62 pub struct PostLike {
63   pub id: i32,
64   pub post_id: PostId,
65   pub person_id: PersonId,
66   pub score: i16,
67   pub published: chrono::NaiveDateTime,
68 }
69
70 #[derive(Clone)]
71 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
72 #[cfg_attr(feature = "full", table_name = "post_like")]
73 pub struct PostLikeForm {
74   pub post_id: PostId,
75   pub person_id: PersonId,
76   pub score: i16,
77 }
78
79 #[derive(PartialEq, Debug)]
80 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
81 #[cfg_attr(feature = "full", belongs_to(Post))]
82 #[cfg_attr(feature = "full", table_name = "post_saved")]
83 pub struct PostSaved {
84   pub id: i32,
85   pub post_id: PostId,
86   pub person_id: PersonId,
87   pub published: chrono::NaiveDateTime,
88 }
89
90 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
91 #[cfg_attr(feature = "full", table_name = "post_saved")]
92 pub struct PostSavedForm {
93   pub post_id: PostId,
94   pub person_id: PersonId,
95 }
96
97 #[derive(PartialEq, Debug)]
98 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
99 #[cfg_attr(feature = "full", belongs_to(Post))]
100 #[cfg_attr(feature = "full", table_name = "post_read")]
101 pub struct PostRead {
102   pub id: i32,
103   pub post_id: PostId,
104   pub person_id: PersonId,
105   pub published: chrono::NaiveDateTime,
106 }
107
108 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
109 #[cfg_attr(feature = "full", table_name = "post_read")]
110 pub struct PostReadForm {
111   pub post_id: PostId,
112   pub person_id: PersonId,
113 }