]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
2630737a2df9dc19073bc9424e90b7958a3ac422
[lemmy.git] / crates / db_schema / src / source / community.rs
1 use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId};
2 #[cfg(feature = "full")]
3 use crate::schema::{community, community_follower, community_moderator, community_person_ban};
4 use serde::{Deserialize, Serialize};
5 use typed_builder::TypedBuilder;
6
7 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
8 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
9 #[cfg_attr(feature = "full", diesel(table_name = community))]
10 pub struct Community {
11   pub id: CommunityId,
12   pub name: String,
13   pub title: String,
14   pub description: Option<String>,
15   pub removed: bool,
16   pub published: chrono::NaiveDateTime,
17   pub updated: Option<chrono::NaiveDateTime>,
18   pub deleted: bool,
19   pub nsfw: bool,
20   pub actor_id: DbUrl,
21   pub local: bool,
22   pub private_key: Option<String>,
23   pub public_key: String,
24   pub last_refreshed_at: chrono::NaiveDateTime,
25   pub icon: Option<DbUrl>,
26   pub banner: Option<DbUrl>,
27   pub followers_url: DbUrl,
28   pub inbox_url: DbUrl,
29   pub shared_inbox_url: Option<DbUrl>,
30   pub hidden: bool,
31   pub posting_restricted_to_mods: bool,
32   pub instance_id: InstanceId,
33 }
34
35 /// A safe representation of community, without the sensitive info
36 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
37 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
38 #[cfg_attr(feature = "full", diesel(table_name = community))]
39 pub struct CommunitySafe {
40   pub id: CommunityId,
41   pub name: String,
42   pub title: String,
43   pub description: Option<String>,
44   pub removed: bool,
45   pub published: chrono::NaiveDateTime,
46   pub updated: Option<chrono::NaiveDateTime>,
47   pub deleted: bool,
48   pub nsfw: bool,
49   pub actor_id: DbUrl,
50   pub local: bool,
51   pub icon: Option<DbUrl>,
52   pub banner: Option<DbUrl>,
53   pub hidden: bool,
54   pub posting_restricted_to_mods: bool,
55   pub instance_id: InstanceId,
56 }
57
58 #[derive(Debug, Clone, TypedBuilder)]
59 #[builder(field_defaults(default))]
60 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
61 #[cfg_attr(feature = "full", diesel(table_name = community))]
62 pub struct CommunityInsertForm {
63   #[builder(!default)]
64   pub name: String,
65   #[builder(!default)]
66   pub title: String,
67   pub description: Option<String>,
68   pub removed: Option<bool>,
69   pub published: Option<chrono::NaiveDateTime>,
70   pub updated: Option<chrono::NaiveDateTime>,
71   pub deleted: Option<bool>,
72   pub nsfw: Option<bool>,
73   pub actor_id: Option<DbUrl>,
74   pub local: Option<bool>,
75   pub private_key: Option<String>,
76   pub public_key: String,
77   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
78   pub icon: Option<DbUrl>,
79   pub banner: Option<DbUrl>,
80   pub followers_url: Option<DbUrl>,
81   pub inbox_url: Option<DbUrl>,
82   pub shared_inbox_url: Option<DbUrl>,
83   pub hidden: Option<bool>,
84   pub posting_restricted_to_mods: Option<bool>,
85   #[builder(!default)]
86   pub instance_id: InstanceId,
87 }
88
89 #[derive(Debug, Clone, TypedBuilder)]
90 #[builder(field_defaults(default))]
91 #[cfg_attr(feature = "full", derive(AsChangeset))]
92 #[cfg_attr(feature = "full", diesel(table_name = community))]
93 pub struct CommunityUpdateForm {
94   pub title: Option<String>,
95   pub description: Option<Option<String>>,
96   pub removed: Option<bool>,
97   pub published: Option<chrono::NaiveDateTime>,
98   pub updated: Option<Option<chrono::NaiveDateTime>>,
99   pub deleted: Option<bool>,
100   pub nsfw: Option<bool>,
101   pub actor_id: Option<DbUrl>,
102   pub local: Option<bool>,
103   pub public_key: Option<String>,
104   pub private_key: Option<Option<String>>,
105   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
106   pub icon: Option<Option<DbUrl>>,
107   pub banner: Option<Option<DbUrl>>,
108   pub followers_url: Option<DbUrl>,
109   pub inbox_url: Option<DbUrl>,
110   pub shared_inbox_url: Option<Option<DbUrl>>,
111   pub hidden: Option<bool>,
112   pub posting_restricted_to_mods: Option<bool>,
113 }
114
115 #[derive(PartialEq, Eq, Debug)]
116 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
117 #[cfg_attr(
118   feature = "full",
119   diesel(belongs_to(crate::source::community::Community))
120 )]
121 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
122 pub struct CommunityModerator {
123   pub id: i32,
124   pub community_id: CommunityId,
125   pub person_id: PersonId,
126   pub published: chrono::NaiveDateTime,
127 }
128
129 #[derive(Clone)]
130 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
131 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
132 pub struct CommunityModeratorForm {
133   pub community_id: CommunityId,
134   pub person_id: PersonId,
135 }
136
137 #[derive(PartialEq, Eq, Debug)]
138 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
139 #[cfg_attr(
140   feature = "full",
141   diesel(belongs_to(crate::source::community::Community))
142 )]
143 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
144 pub struct CommunityPersonBan {
145   pub id: i32,
146   pub community_id: CommunityId,
147   pub person_id: PersonId,
148   pub published: chrono::NaiveDateTime,
149   pub expires: Option<chrono::NaiveDateTime>,
150 }
151
152 #[derive(Clone)]
153 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
154 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
155 pub struct CommunityPersonBanForm {
156   pub community_id: CommunityId,
157   pub person_id: PersonId,
158   pub expires: Option<Option<chrono::NaiveDateTime>>,
159 }
160
161 #[derive(PartialEq, Eq, Debug)]
162 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
163 #[cfg_attr(
164   feature = "full",
165   diesel(belongs_to(crate::source::community::Community))
166 )]
167 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
168 pub struct CommunityFollower {
169   pub id: i32,
170   pub community_id: CommunityId,
171   pub person_id: PersonId,
172   pub published: chrono::NaiveDateTime,
173   pub pending: bool,
174 }
175
176 #[derive(Clone)]
177 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
178 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
179 pub struct CommunityFollowerForm {
180   pub community_id: CommunityId,
181   pub person_id: PersonId,
182   pub pending: bool,
183 }