1 use crate::structs::AdminPurgePersonView;
2 use diesel::{result::Error, *};
5 schema::{admin_purge_person, person},
7 moderator::AdminPurgePerson,
8 person::{Person, PersonSafe},
10 traits::{ToSafe, ViewToVec},
11 utils::limit_and_offset,
14 type AdminPurgePersonViewTuple = (AdminPurgePerson, PersonSafe);
16 impl AdminPurgePersonView {
19 admin_person_id: Option<PersonId>,
22 ) -> Result<Vec<Self>, Error> {
23 let mut query = admin_purge_person::table
24 .inner_join(person::table.on(admin_purge_person::admin_person_id.eq(person::id)))
26 admin_purge_person::all_columns,
27 Person::safe_columns_tuple(),
31 if let Some(admin_person_id) = admin_person_id {
32 query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
35 let (limit, offset) = limit_and_offset(page, limit);
40 .order_by(admin_purge_person::when_.desc())
41 .load::<AdminPurgePersonViewTuple>(conn)?;
43 Ok(Self::from_tuple_to_vec(res))
47 impl ViewToVec for AdminPurgePersonView {
48 type DbTuple = AdminPurgePersonViewTuple;
49 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
53 admin_purge_person: a.0.to_owned(),
54 admin: a.1.to_owned(),
56 .collect::<Vec<Self>>()