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