1 use crate::structs::ModAddView;
2 use diesel::{result::Error, *};
5 schema::{mod_add, person, person_alias_1},
8 person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
10 traits::{ToSafe, ViewToVec},
11 utils::limit_and_offset,
14 type ModAddViewTuple = (ModAdd, PersonSafe, PersonSafeAlias1);
19 mod_person_id: Option<PersonId>,
22 ) -> Result<Vec<Self>, Error> {
23 let mut query = mod_add::table
24 .inner_join(person::table.on(mod_add::mod_person_id.eq(person::id)))
25 .inner_join(person_alias_1::table.on(mod_add::other_person_id.eq(person_alias_1::id)))
28 Person::safe_columns_tuple(),
29 PersonAlias1::safe_columns_tuple(),
33 if let Some(mod_person_id) = mod_person_id {
34 query = query.filter(mod_add::mod_person_id.eq(mod_person_id));
37 let (limit, offset) = limit_and_offset(page, limit)?;
42 .order_by(mod_add::when_.desc())
43 .load::<ModAddViewTuple>(conn)?;
45 Ok(Self::from_tuple_to_vec(res))
49 impl ViewToVec for ModAddView {
50 type DbTuple = ModAddViewTuple;
51 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
55 mod_add: a.0.to_owned(),
56 moderator: a.1.to_owned(),
57 modded_person: a.2.to_owned(),
59 .collect::<Vec<Self>>()