1 use diesel::{result::Error, *};
2 use lemmy_db_queries::{ToSafe, ViewToVec};
4 schema::{person, person_alias_1, person_block},
5 source::person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
10 #[derive(Debug, Serialize, Clone)]
11 pub struct PersonBlockView {
12 pub person: PersonSafe,
13 pub target: PersonSafeAlias1,
16 type PersonBlockViewTuple = (PersonSafe, PersonSafeAlias1);
18 impl PersonBlockView {
19 pub fn for_person(conn: &PgConnection, person_id: PersonId) -> Result<Vec<Self>, Error> {
20 let res = person_block::table
21 .inner_join(person::table)
22 .inner_join(person_alias_1::table) // TODO I dont know if this will be smart abt the column
24 Person::safe_columns_tuple(),
25 PersonAlias1::safe_columns_tuple(),
27 .filter(person_block::person_id.eq(person_id))
28 .order_by(person_block::published)
29 .load::<PersonBlockViewTuple>(conn)?;
31 Ok(Self::from_tuple_to_vec(res))
35 impl ViewToVec for PersonBlockView {
36 type DbTuple = PersonBlockViewTuple;
37 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
41 person: a.0.to_owned(),
42 target: a.1.to_owned(),
44 .collect::<Vec<Self>>()