1 use crate::structs::{AdminPurgePersonView, ModlogListParams};
8 NullableExpressionMethods,
11 use diesel_async::RunQueryDsl;
12 use lemmy_db_schema::{
14 schema::{admin_purge_person, person},
16 moderator::AdminPurgePerson,
17 person::{Person, PersonSafe},
19 traits::{ToSafe, ViewToVec},
20 utils::{get_conn, limit_and_offset, DbPool},
23 type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<PersonSafe>);
25 impl AdminPurgePersonView {
26 pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
27 let conn = &mut get_conn(pool).await?;
29 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
30 let show_mod_names = !params.hide_modlog_names;
31 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
33 let admin_names_join = admin_purge_person::admin_person_id
35 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
36 let mut query = admin_purge_person::table
37 .left_join(person::table.on(admin_names_join))
39 admin_purge_person::all_columns,
40 Person::safe_columns_tuple().nullable(),
44 if let Some(admin_person_id) = params.mod_person_id {
45 query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
48 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
53 .order_by(admin_purge_person::when_.desc())
54 .load::<AdminPurgePersonViewTuple>(conn)
57 let results = Self::from_tuple_to_vec(res);
62 impl ViewToVec for AdminPurgePersonView {
63 type DbTuple = AdminPurgePersonViewTuple;
64 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
68 admin_purge_person: a.0,
71 .collect::<Vec<Self>>()