1 use crate::structs::{ModTransferCommunityView, ModlogListParams};
8 NullableExpressionMethods,
11 use diesel_async::RunQueryDsl;
12 use lemmy_db_schema::{
14 schema::{community, mod_transfer_community, person},
15 source::{community::Community, moderator::ModTransferCommunity, person::Person},
17 utils::{get_conn, limit_and_offset, DbPool},
20 type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
22 impl ModTransferCommunityView {
23 pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
24 let conn = &mut get_conn(pool).await?;
26 let person_alias_1 = diesel::alias!(person as person1);
27 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
28 let show_mod_names = !params.hide_modlog_names;
29 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
31 let admin_names_join = mod_transfer_community::mod_person_id
33 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
34 let mut query = mod_transfer_community::table
35 .left_join(person::table.on(admin_names_join))
36 .inner_join(community::table)
39 .on(mod_transfer_community::other_person_id.eq(person_alias_1.field(person::id))),
42 mod_transfer_community::all_columns,
43 person::all_columns.nullable(),
44 community::all_columns,
45 person_alias_1.fields(person::all_columns),
49 if let Some(mod_person_id) = params.mod_person_id {
50 query = query.filter(mod_transfer_community::mod_person_id.eq(mod_person_id));
53 if let Some(community_id) = params.community_id {
54 query = query.filter(mod_transfer_community::community_id.eq(community_id));
57 if let Some(other_person_id) = params.other_person_id {
58 query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
61 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
66 .order_by(mod_transfer_community::when_.desc())
67 .load::<ModTransferCommunityViewTuple>(conn)
70 let results = res.into_iter().map(Self::from_tuple).collect();
75 impl JoinView for ModTransferCommunityView {
76 type JoinTuple = ModTransferCommunityViewTuple;
77 fn from_tuple(a: Self::JoinTuple) -> Self {
79 mod_transfer_community: a.0,