]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
35b695db0448b0453a43e11b034d3738eb9447c8
[lemmy.git] / crates / db_schema / src / source / community.rs
1 use crate::{
2   newtypes::{CommunityId, DbUrl, PersonId},
3   schema::{community, community_follower, community_moderator, community_person_ban},
4 };
5 use serde::{Deserialize, Serialize};
6
7 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
8 #[table_name = "community"]
9 pub struct Community {
10   pub id: CommunityId,
11   pub name: String,
12   pub title: String,
13   pub description: Option<String>,
14   pub removed: bool,
15   pub published: chrono::NaiveDateTime,
16   pub updated: Option<chrono::NaiveDateTime>,
17   pub deleted: bool,
18   pub nsfw: bool,
19   pub actor_id: DbUrl,
20   pub local: bool,
21   pub private_key: Option<String>,
22   pub public_key: String,
23   pub last_refreshed_at: chrono::NaiveDateTime,
24   pub icon: Option<DbUrl>,
25   pub banner: Option<DbUrl>,
26   pub followers_url: DbUrl,
27   pub inbox_url: DbUrl,
28   pub shared_inbox_url: Option<DbUrl>,
29   pub hidden: bool,
30 }
31
32 /// A safe representation of community, without the sensitive info
33 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
34 #[table_name = "community"]
35 pub struct CommunitySafe {
36   pub id: CommunityId,
37   pub name: String,
38   pub title: String,
39   pub description: Option<String>,
40   pub removed: bool,
41   pub published: chrono::NaiveDateTime,
42   pub updated: Option<chrono::NaiveDateTime>,
43   pub deleted: bool,
44   pub nsfw: bool,
45   pub actor_id: DbUrl,
46   pub local: bool,
47   pub icon: Option<DbUrl>,
48   pub banner: Option<DbUrl>,
49   pub hidden: bool,
50 }
51
52 #[derive(Insertable, AsChangeset, Debug, Default)]
53 #[table_name = "community"]
54 pub struct CommunityForm {
55   pub name: String,
56   pub title: String,
57   pub description: Option<String>,
58   pub removed: Option<bool>,
59   pub published: Option<chrono::NaiveDateTime>,
60   pub updated: Option<chrono::NaiveDateTime>,
61   pub deleted: Option<bool>,
62   pub nsfw: Option<bool>,
63   pub actor_id: Option<DbUrl>,
64   pub local: Option<bool>,
65   pub private_key: Option<Option<String>>,
66   pub public_key: String,
67   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
68   pub icon: Option<Option<DbUrl>>,
69   pub banner: Option<Option<DbUrl>>,
70   pub followers_url: Option<DbUrl>,
71   pub inbox_url: Option<DbUrl>,
72   pub shared_inbox_url: Option<Option<DbUrl>>,
73   pub hidden: Option<bool>,
74 }
75
76 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
77 #[belongs_to(Community)]
78 #[table_name = "community_moderator"]
79 pub struct CommunityModerator {
80   pub id: i32,
81   pub community_id: CommunityId,
82   pub person_id: PersonId,
83   pub published: chrono::NaiveDateTime,
84 }
85
86 #[derive(Insertable, AsChangeset, Clone)]
87 #[table_name = "community_moderator"]
88 pub struct CommunityModeratorForm {
89   pub community_id: CommunityId,
90   pub person_id: PersonId,
91 }
92
93 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
94 #[belongs_to(Community)]
95 #[table_name = "community_person_ban"]
96 pub struct CommunityPersonBan {
97   pub id: i32,
98   pub community_id: CommunityId,
99   pub person_id: PersonId,
100   pub published: chrono::NaiveDateTime,
101   pub expires: Option<chrono::NaiveDateTime>,
102 }
103
104 #[derive(Insertable, AsChangeset, Clone)]
105 #[table_name = "community_person_ban"]
106 pub struct CommunityPersonBanForm {
107   pub community_id: CommunityId,
108   pub person_id: PersonId,
109   pub expires: Option<Option<chrono::NaiveDateTime>>,
110 }
111
112 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
113 #[belongs_to(Community)]
114 #[table_name = "community_follower"]
115 pub struct CommunityFollower {
116   pub id: i32,
117   pub community_id: CommunityId,
118   pub person_id: PersonId,
119   pub published: chrono::NaiveDateTime,
120   pub pending: Option<bool>,
121 }
122
123 #[derive(Insertable, AsChangeset, Clone)]
124 #[table_name = "community_follower"]
125 pub struct CommunityFollowerForm {
126   pub community_id: CommunityId,
127   pub person_id: PersonId,
128   pub pending: bool,
129 }