use lemmy_db_schema::{
newtypes::PersonId,
schema::{mod_add, person},
- source::{
- moderator::ModAdd,
- person::{Person, PersonSafe},
- },
- traits::{ToSafe, ViewToVec},
+ source::{moderator::ModAdd, person::Person},
+ traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
-type ModAddViewTuple = (ModAdd, Option<PersonSafe>, PersonSafe);
+type ModAddViewTuple = (ModAdd, Option<Person>, Person);
impl ModAddView {
- pub async fn list(pool: &DbPool, 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));
.inner_join(person_alias_1.on(mod_add::other_person_id.eq(person_alias_1.field(person::id))))
.select((
mod_add::all_columns,
- Person::safe_columns_tuple().nullable(),
- person_alias_1.fields(Person::safe_columns_tuple()),
+ person::all_columns.nullable(),
+ person_alias_1.fields(person::all_columns),
))
.into_boxed();
.load::<ModAddViewTuple>(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 ModAddView {
- type DbTuple = ModAddViewTuple;
- fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
- items
- .into_iter()
- .map(|a| Self {
- mod_add: a.0,
- moderator: a.1,
- modded_person: a.2,
- })
- .collect::<Vec<Self>>()
+impl JoinView for ModAddView {
+ type JoinTuple = ModAddViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ mod_add: a.0,
+ moderator: a.1,
+ modded_person: a.2,
+ }
}
}