1 use crate::structs::CommunityBlockView;
2 use diesel::{result::Error, *};
5 schema::{community, community_block, person},
7 community::{Community, CommunitySafe},
8 person::{Person, PersonSafe},
10 traits::{ToSafe, ViewToVec},
13 type CommunityBlockViewTuple = (PersonSafe, CommunitySafe);
15 impl CommunityBlockView {
16 pub fn for_person(conn: &PgConnection, person_id: PersonId) -> Result<Vec<Self>, Error> {
17 let res = community_block::table
18 .inner_join(person::table)
19 .inner_join(community::table)
21 Person::safe_columns_tuple(),
22 Community::safe_columns_tuple(),
24 .filter(community_block::person_id.eq(person_id))
25 .order_by(community_block::published)
26 .load::<CommunityBlockViewTuple>(conn)?;
28 Ok(Self::from_tuple_to_vec(res))
32 impl ViewToVec for CommunityBlockView {
33 type DbTuple = CommunityBlockViewTuple;
34 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
41 .collect::<Vec<Self>>()