1 use crate::structs::{AdminPurgePersonView, ModlogListParams};
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, Option<PersonSafe>);
16 impl AdminPurgePersonView {
17 pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
18 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
19 let show_mod_names = !params.hide_modlog_names;
20 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
22 let admin_names_join = admin_purge_person::admin_person_id
24 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
25 let mut query = admin_purge_person::table
26 .left_join(person::table.on(admin_names_join))
28 admin_purge_person::all_columns,
29 Person::safe_columns_tuple().nullable(),
33 if let Some(admin_person_id) = params.mod_person_id {
34 query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
37 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
42 .order_by(admin_purge_person::when_.desc())
43 .load::<AdminPurgePersonViewTuple>(conn)?;
45 let results = Self::from_tuple_to_vec(res);
50 impl ViewToVec for AdminPurgePersonView {
51 type DbTuple = AdminPurgePersonViewTuple;
52 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
56 admin_purge_person: a.0,
59 .collect::<Vec<Self>>()