]> Untitled Git - lemmy.git/blob - server/lemmy_db/src/moderator_views.rs
efa949a4af10ebce247f466e522906c313c9dcd7
[lemmy.git] / server / lemmy_db / src / moderator_views.rs
1 use crate::limit_and_offset;
2 use diesel::{result::Error, *};
3 use serde::Serialize;
4
5 table! {
6   mod_remove_post_view (id) {
7     id -> Int4,
8     mod_user_id -> Int4,
9     post_id -> Int4,
10     reason -> Nullable<Text>,
11     removed -> Nullable<Bool>,
12     when_ -> Timestamp,
13     mod_user_name -> Varchar,
14     post_name -> Varchar,
15     community_id -> Int4,
16     community_name -> Varchar,
17   }
18 }
19
20 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
21 #[table_name = "mod_remove_post_view"]
22 pub struct ModRemovePostView {
23   pub id: i32,
24   pub mod_user_id: i32,
25   pub post_id: i32,
26   pub reason: Option<String>,
27   pub removed: Option<bool>,
28   pub when_: chrono::NaiveDateTime,
29   pub mod_user_name: String,
30   pub post_name: String,
31   pub community_id: i32,
32   pub community_name: String,
33 }
34
35 impl ModRemovePostView {
36   pub fn list(
37     conn: &PgConnection,
38     from_community_id: Option<i32>,
39     from_mod_user_id: Option<i32>,
40     page: Option<i64>,
41     limit: Option<i64>,
42   ) -> Result<Vec<Self>, Error> {
43     use super::moderator_views::mod_remove_post_view::dsl::*;
44     let mut query = mod_remove_post_view.into_boxed();
45
46     let (limit, offset) = limit_and_offset(page, limit);
47
48     if let Some(from_community_id) = from_community_id {
49       query = query.filter(community_id.eq(from_community_id));
50     };
51
52     if let Some(from_mod_user_id) = from_mod_user_id {
53       query = query.filter(mod_user_id.eq(from_mod_user_id));
54     };
55
56     query
57       .limit(limit)
58       .offset(offset)
59       .order_by(when_.desc())
60       .load::<Self>(conn)
61   }
62 }
63
64 table! {
65   mod_lock_post_view (id) {
66     id -> Int4,
67     mod_user_id -> Int4,
68     post_id -> Int4,
69     locked -> Nullable<Bool>,
70     when_ -> Timestamp,
71     mod_user_name -> Varchar,
72     post_name -> Varchar,
73     community_id -> Int4,
74     community_name -> Varchar,
75   }
76 }
77
78 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
79 #[table_name = "mod_lock_post_view"]
80 pub struct ModLockPostView {
81   pub id: i32,
82   pub mod_user_id: i32,
83   pub post_id: i32,
84   pub locked: Option<bool>,
85   pub when_: chrono::NaiveDateTime,
86   pub mod_user_name: String,
87   pub post_name: String,
88   pub community_id: i32,
89   pub community_name: String,
90 }
91
92 impl ModLockPostView {
93   pub fn list(
94     conn: &PgConnection,
95     from_community_id: Option<i32>,
96     from_mod_user_id: Option<i32>,
97     page: Option<i64>,
98     limit: Option<i64>,
99   ) -> Result<Vec<Self>, Error> {
100     use super::moderator_views::mod_lock_post_view::dsl::*;
101     let mut query = mod_lock_post_view.into_boxed();
102
103     let (limit, offset) = limit_and_offset(page, limit);
104
105     if let Some(from_community_id) = from_community_id {
106       query = query.filter(community_id.eq(from_community_id));
107     };
108
109     if let Some(from_mod_user_id) = from_mod_user_id {
110       query = query.filter(mod_user_id.eq(from_mod_user_id));
111     };
112
113     query
114       .limit(limit)
115       .offset(offset)
116       .order_by(when_.desc())
117       .load::<Self>(conn)
118   }
119 }
120
121 table! {
122   mod_sticky_post_view (id) {
123     id -> Int4,
124     mod_user_id -> Int4,
125     post_id -> Int4,
126     stickied -> Nullable<Bool>,
127     when_ -> Timestamp,
128     mod_user_name -> Varchar,
129     post_name -> Varchar,
130     community_id -> Int4,
131     community_name -> Varchar,
132   }
133 }
134
135 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
136 #[table_name = "mod_sticky_post_view"]
137 pub struct ModStickyPostView {
138   pub id: i32,
139   pub mod_user_id: i32,
140   pub post_id: i32,
141   pub stickied: Option<bool>,
142   pub when_: chrono::NaiveDateTime,
143   pub mod_user_name: String,
144   pub post_name: String,
145   pub community_id: i32,
146   pub community_name: String,
147 }
148
149 impl ModStickyPostView {
150   pub fn list(
151     conn: &PgConnection,
152     from_community_id: Option<i32>,
153     from_mod_user_id: Option<i32>,
154     page: Option<i64>,
155     limit: Option<i64>,
156   ) -> Result<Vec<Self>, Error> {
157     use super::moderator_views::mod_sticky_post_view::dsl::*;
158     let mut query = mod_sticky_post_view.into_boxed();
159
160     let (limit, offset) = limit_and_offset(page, limit);
161
162     if let Some(from_community_id) = from_community_id {
163       query = query.filter(community_id.eq(from_community_id));
164     };
165
166     if let Some(from_mod_user_id) = from_mod_user_id {
167       query = query.filter(mod_user_id.eq(from_mod_user_id));
168     };
169
170     query
171       .limit(limit)
172       .offset(offset)
173       .order_by(when_.desc())
174       .load::<Self>(conn)
175   }
176 }
177
178 table! {
179   mod_remove_comment_view (id) {
180     id -> Int4,
181     mod_user_id -> Int4,
182     comment_id -> Int4,
183     reason -> Nullable<Text>,
184     removed -> Nullable<Bool>,
185     when_ -> Timestamp,
186     mod_user_name -> Varchar,
187     comment_user_id -> Int4,
188     comment_user_name -> Varchar,
189     comment_content -> Text,
190     post_id -> Int4,
191     post_name -> Varchar,
192     community_id -> Int4,
193     community_name -> Varchar,
194   }
195 }
196
197 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
198 #[table_name = "mod_remove_comment_view"]
199 pub struct ModRemoveCommentView {
200   pub id: i32,
201   pub mod_user_id: i32,
202   pub comment_id: i32,
203   pub reason: Option<String>,
204   pub removed: Option<bool>,
205   pub when_: chrono::NaiveDateTime,
206   pub mod_user_name: String,
207   pub comment_user_id: i32,
208   pub comment_user_name: String,
209   pub comment_content: String,
210   pub post_id: i32,
211   pub post_name: String,
212   pub community_id: i32,
213   pub community_name: String,
214 }
215
216 impl ModRemoveCommentView {
217   pub fn list(
218     conn: &PgConnection,
219     from_community_id: Option<i32>,
220     from_mod_user_id: Option<i32>,
221     page: Option<i64>,
222     limit: Option<i64>,
223   ) -> Result<Vec<Self>, Error> {
224     use super::moderator_views::mod_remove_comment_view::dsl::*;
225     let mut query = mod_remove_comment_view.into_boxed();
226
227     let (limit, offset) = limit_and_offset(page, limit);
228
229     if let Some(from_community_id) = from_community_id {
230       query = query.filter(community_id.eq(from_community_id));
231     };
232
233     if let Some(from_mod_user_id) = from_mod_user_id {
234       query = query.filter(mod_user_id.eq(from_mod_user_id));
235     };
236
237     query
238       .limit(limit)
239       .offset(offset)
240       .order_by(when_.desc())
241       .load::<Self>(conn)
242   }
243 }
244
245 table! {
246   mod_remove_community_view (id) {
247     id -> Int4,
248     mod_user_id -> Int4,
249     community_id -> Int4,
250     reason -> Nullable<Text>,
251     removed -> Nullable<Bool>,
252     expires -> Nullable<Timestamp>,
253     when_ -> Timestamp,
254     mod_user_name -> Varchar,
255     community_name -> Varchar,
256   }
257 }
258
259 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
260 #[table_name = "mod_remove_community_view"]
261 pub struct ModRemoveCommunityView {
262   pub id: i32,
263   pub mod_user_id: i32,
264   pub community_id: i32,
265   pub reason: Option<String>,
266   pub removed: Option<bool>,
267   pub expires: Option<chrono::NaiveDateTime>,
268   pub when_: chrono::NaiveDateTime,
269   pub mod_user_name: String,
270   pub community_name: String,
271 }
272
273 impl ModRemoveCommunityView {
274   pub fn list(
275     conn: &PgConnection,
276     from_mod_user_id: Option<i32>,
277     page: Option<i64>,
278     limit: Option<i64>,
279   ) -> Result<Vec<Self>, Error> {
280     use super::moderator_views::mod_remove_community_view::dsl::*;
281     let mut query = mod_remove_community_view.into_boxed();
282
283     let (limit, offset) = limit_and_offset(page, limit);
284
285     if let Some(from_mod_user_id) = from_mod_user_id {
286       query = query.filter(mod_user_id.eq(from_mod_user_id));
287     };
288
289     query
290       .limit(limit)
291       .offset(offset)
292       .order_by(when_.desc())
293       .load::<Self>(conn)
294   }
295 }
296
297 table! {
298   mod_ban_from_community_view (id) {
299     id -> Int4,
300     mod_user_id -> Int4,
301     other_user_id -> Int4,
302     community_id -> Int4,
303     reason -> Nullable<Text>,
304     banned -> Nullable<Bool>,
305     expires -> Nullable<Timestamp>,
306     when_ -> Timestamp,
307     mod_user_name -> Varchar,
308     other_user_name -> Varchar,
309     community_name -> Varchar,
310   }
311 }
312
313 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
314 #[table_name = "mod_ban_from_community_view"]
315 pub struct ModBanFromCommunityView {
316   pub id: i32,
317   pub mod_user_id: i32,
318   pub other_user_id: i32,
319   pub community_id: i32,
320   pub reason: Option<String>,
321   pub banned: Option<bool>,
322   pub expires: Option<chrono::NaiveDateTime>,
323   pub when_: chrono::NaiveDateTime,
324   pub mod_user_name: String,
325   pub other_user_name: String,
326   pub community_name: String,
327 }
328
329 impl ModBanFromCommunityView {
330   pub fn list(
331     conn: &PgConnection,
332     from_community_id: Option<i32>,
333     from_mod_user_id: Option<i32>,
334     page: Option<i64>,
335     limit: Option<i64>,
336   ) -> Result<Vec<Self>, Error> {
337     use super::moderator_views::mod_ban_from_community_view::dsl::*;
338     let mut query = mod_ban_from_community_view.into_boxed();
339
340     let (limit, offset) = limit_and_offset(page, limit);
341
342     if let Some(from_community_id) = from_community_id {
343       query = query.filter(community_id.eq(from_community_id));
344     };
345
346     if let Some(from_mod_user_id) = from_mod_user_id {
347       query = query.filter(mod_user_id.eq(from_mod_user_id));
348     };
349
350     query
351       .limit(limit)
352       .offset(offset)
353       .order_by(when_.desc())
354       .load::<Self>(conn)
355   }
356 }
357
358 table! {
359   mod_ban_view (id) {
360     id -> Int4,
361     mod_user_id -> Int4,
362     other_user_id -> Int4,
363     reason -> Nullable<Text>,
364     banned -> Nullable<Bool>,
365     expires -> Nullable<Timestamp>,
366     when_ -> Timestamp,
367     mod_user_name -> Varchar,
368     other_user_name -> Varchar,
369   }
370 }
371
372 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
373 #[table_name = "mod_ban_view"]
374 pub struct ModBanView {
375   pub id: i32,
376   pub mod_user_id: i32,
377   pub other_user_id: i32,
378   pub reason: Option<String>,
379   pub banned: Option<bool>,
380   pub expires: Option<chrono::NaiveDateTime>,
381   pub when_: chrono::NaiveDateTime,
382   pub mod_user_name: String,
383   pub other_user_name: String,
384 }
385
386 impl ModBanView {
387   pub fn list(
388     conn: &PgConnection,
389     from_mod_user_id: Option<i32>,
390     page: Option<i64>,
391     limit: Option<i64>,
392   ) -> Result<Vec<Self>, Error> {
393     use super::moderator_views::mod_ban_view::dsl::*;
394     let mut query = mod_ban_view.into_boxed();
395
396     let (limit, offset) = limit_and_offset(page, limit);
397
398     if let Some(from_mod_user_id) = from_mod_user_id {
399       query = query.filter(mod_user_id.eq(from_mod_user_id));
400     };
401
402     query
403       .limit(limit)
404       .offset(offset)
405       .order_by(when_.desc())
406       .load::<Self>(conn)
407   }
408 }
409
410 table! {
411   mod_add_community_view (id) {
412     id -> Int4,
413     mod_user_id -> Int4,
414     other_user_id -> Int4,
415     community_id -> Int4,
416     removed -> Nullable<Bool>,
417     when_ -> Timestamp,
418     mod_user_name -> Varchar,
419     other_user_name -> Varchar,
420     community_name -> Varchar,
421   }
422 }
423
424 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
425 #[table_name = "mod_add_community_view"]
426 pub struct ModAddCommunityView {
427   pub id: i32,
428   pub mod_user_id: i32,
429   pub other_user_id: i32,
430   pub community_id: i32,
431   pub removed: Option<bool>,
432   pub when_: chrono::NaiveDateTime,
433   pub mod_user_name: String,
434   pub other_user_name: String,
435   pub community_name: String,
436 }
437
438 impl ModAddCommunityView {
439   pub fn list(
440     conn: &PgConnection,
441     from_community_id: Option<i32>,
442     from_mod_user_id: Option<i32>,
443     page: Option<i64>,
444     limit: Option<i64>,
445   ) -> Result<Vec<Self>, Error> {
446     use super::moderator_views::mod_add_community_view::dsl::*;
447     let mut query = mod_add_community_view.into_boxed();
448
449     let (limit, offset) = limit_and_offset(page, limit);
450
451     if let Some(from_community_id) = from_community_id {
452       query = query.filter(community_id.eq(from_community_id));
453     };
454
455     if let Some(from_mod_user_id) = from_mod_user_id {
456       query = query.filter(mod_user_id.eq(from_mod_user_id));
457     };
458
459     query
460       .limit(limit)
461       .offset(offset)
462       .order_by(when_.desc())
463       .load::<Self>(conn)
464   }
465 }
466
467 table! {
468   mod_add_view (id) {
469     id -> Int4,
470     mod_user_id -> Int4,
471     other_user_id -> Int4,
472     removed -> Nullable<Bool>,
473     when_ -> Timestamp,
474     mod_user_name -> Varchar,
475     other_user_name -> Varchar,
476   }
477 }
478
479 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
480 #[table_name = "mod_add_view"]
481 pub struct ModAddView {
482   pub id: i32,
483   pub mod_user_id: i32,
484   pub other_user_id: i32,
485   pub removed: Option<bool>,
486   pub when_: chrono::NaiveDateTime,
487   pub mod_user_name: String,
488   pub other_user_name: String,
489 }
490
491 impl ModAddView {
492   pub fn list(
493     conn: &PgConnection,
494     from_mod_user_id: Option<i32>,
495     page: Option<i64>,
496     limit: Option<i64>,
497   ) -> Result<Vec<Self>, Error> {
498     use super::moderator_views::mod_add_view::dsl::*;
499     let mut query = mod_add_view.into_boxed();
500
501     let (limit, offset) = limit_and_offset(page, limit);
502
503     if let Some(from_mod_user_id) = from_mod_user_id {
504       query = query.filter(mod_user_id.eq(from_mod_user_id));
505     };
506
507     query
508       .limit(limit)
509       .offset(offset)
510       .order_by(when_.desc())
511       .load::<Self>(conn)
512   }
513 }