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