use lemmy_db_schema::{
newtypes::PersonId,
schema::{mod_ban, person},
- source::{
- moderator::ModBan,
- person::{Person, PersonSafe},
- },
- traits::{ToSafe, ViewToVec},
+ source::{moderator::ModBan, person::Person},
+ traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
-type ModBanViewTuple = (ModBan, Option<PersonSafe>, PersonSafe);
+type ModBanViewTuple = (ModBan, Option<Person>, Person);
impl ModBanView {
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
.inner_join(person_alias_1.on(mod_ban::other_person_id.eq(person_alias_1.field(person::id))))
.select((
mod_ban::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::<ModBanViewTuple>(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 ModBanView {
- type DbTuple = ModBanViewTuple;
- fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
- items
- .into_iter()
- .map(|a| Self {
- mod_ban: a.0,
- moderator: a.1,
- banned_person: a.2,
- })
- .collect::<Vec<Self>>()
+impl JoinView for ModBanView {
+ type JoinTuple = ModBanViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ mod_ban: a.0,
+ moderator: a.1,
+ banned_person: a.2,
+ }
}
}