1 use crate::structs::{AdminPurgePersonView, ModlogListParams};
8 NullableExpressionMethods,
11 use diesel_async::RunQueryDsl;
12 use lemmy_db_schema::{
14 schema::{admin_purge_person, person},
15 source::{moderator::AdminPurgePerson, person::Person},
17 utils::{get_conn, limit_and_offset, DbPool},
20 type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
22 impl AdminPurgePersonView {
23 pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
24 let conn = &mut get_conn(pool).await?;
26 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
27 let show_mod_names = !params.hide_modlog_names;
28 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
30 let admin_names_join = admin_purge_person::admin_person_id
32 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
33 let mut query = admin_purge_person::table
34 .left_join(person::table.on(admin_names_join))
36 admin_purge_person::all_columns,
37 person::all_columns.nullable(),
41 if let Some(admin_person_id) = params.mod_person_id {
42 query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
45 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
50 .order_by(admin_purge_person::when_.desc())
51 .load::<AdminPurgePersonViewTuple>(conn)
54 let results = res.into_iter().map(Self::from_tuple).collect();
59 impl JoinView for AdminPurgePersonView {
60 type JoinTuple = AdminPurgePersonViewTuple;
61 fn from_tuple(a: Self::JoinTuple) -> Self {
63 admin_purge_person: a.0,