1 use diesel::{result::Error, *};
5 schema::{mod_add, person, person_alias_1},
8 person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
10 traits::{ToSafe, ViewToVec},
12 use serde::{Deserialize, Serialize};
14 #[derive(Debug, Serialize, Deserialize, Clone)]
15 pub struct ModAddView {
17 pub moderator: PersonSafe,
18 pub modded_person: PersonSafeAlias1,
21 type ModAddViewTuple = (ModAdd, PersonSafe, PersonSafeAlias1);
26 mod_person_id: Option<PersonId>,
29 ) -> Result<Vec<Self>, Error> {
30 let mut query = mod_add::table
31 .inner_join(person::table.on(mod_add::mod_person_id.eq(person::id)))
32 .inner_join(person_alias_1::table.on(mod_add::other_person_id.eq(person_alias_1::id)))
35 Person::safe_columns_tuple(),
36 PersonAlias1::safe_columns_tuple(),
40 if let Some(mod_person_id) = mod_person_id {
41 query = query.filter(mod_add::mod_person_id.eq(mod_person_id));
44 let (limit, offset) = limit_and_offset(page, limit);
49 .order_by(mod_add::when_.desc())
50 .load::<ModAddViewTuple>(conn)?;
52 Ok(Self::from_tuple_to_vec(res))
56 impl ViewToVec for ModAddView {
57 type DbTuple = ModAddViewTuple;
58 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
62 mod_add: a.0.to_owned(),
63 moderator: a.1.to_owned(),
64 modded_person: a.2.to_owned(),
66 .collect::<Vec<Self>>()