use crate::structs::{ModAddCommunityView, ModlogListParams};
-use diesel::{result::Error, *};
+use diesel::{
+ result::Error,
+ BoolExpressionMethods,
+ ExpressionMethods,
+ IntoSql,
+ JoinOnDsl,
+ NullableExpressionMethods,
+ QueryDsl,
+};
+use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::PersonId,
schema::{community, mod_add_community, person},
- source::{
- community::{Community, CommunitySafe},
- moderator::ModAddCommunity,
- person::{Person, PersonSafe},
- },
- traits::{ToSafe, ViewToVec},
- utils::limit_and_offset,
+ source::{community::Community, moderator::ModAddCommunity, person::Person},
+ traits::JoinView,
+ utils::{get_conn, limit_and_offset, DbPool},
};
-type ModAddCommunityViewTuple = (
- ModAddCommunity,
- Option<PersonSafe>,
- CommunitySafe,
- PersonSafe,
-);
+type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
impl ModAddCommunityView {
- pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
let show_mod_names = !params.hide_modlog_names;
)
.select((
mod_add_community::all_columns,
- Person::safe_columns_tuple().nullable(),
- Community::safe_columns_tuple(),
- person_alias_1.fields(Person::safe_columns_tuple()),
+ person::all_columns.nullable(),
+ community::all_columns,
+ person_alias_1.fields(person::all_columns),
))
.into_boxed();
.limit(limit)
.offset(offset)
.order_by(mod_add_community::when_.desc())
- .load::<ModAddCommunityViewTuple>(conn)?;
+ .load::<ModAddCommunityViewTuple>(conn)
+ .await?;
- let results = Self::from_tuple_to_vec(res);
+ let results = res.into_iter().map(Self::from_tuple).collect();
Ok(results)
}
}
-impl ViewToVec for ModAddCommunityView {
- type DbTuple = ModAddCommunityViewTuple;
- fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
- items
- .into_iter()
- .map(|a| Self {
- mod_add_community: a.0,
- moderator: a.1,
- community: a.2,
- modded_person: a.3,
- })
- .collect::<Vec<Self>>()
+impl JoinView for ModAddCommunityView {
+ type JoinTuple = ModAddCommunityViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ mod_add_community: a.0,
+ moderator: a.1,
+ community: a.2,
+ modded_person: a.3,
+ }
}
}