1 use crate::structs::CommunityBlockView;
2 use diesel::{result::Error, ExpressionMethods, QueryDsl};
3 use diesel_async::RunQueryDsl;
6 schema::{community, community_block, person},
7 source::{community::Community, person::Person},
9 utils::{get_conn, DbPool},
12 type CommunityBlockViewTuple = (Person, Community);
14 impl CommunityBlockView {
15 pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
16 let conn = &mut get_conn(pool).await?;
17 let res = community_block::table
18 .inner_join(person::table)
19 .inner_join(community::table)
20 .select((person::all_columns, community::all_columns))
21 .filter(community_block::person_id.eq(person_id))
22 .filter(community::deleted.eq(false))
23 .filter(community::removed.eq(false))
24 .order_by(community_block::published)
25 .load::<CommunityBlockViewTuple>(conn)
28 Ok(res.into_iter().map(Self::from_tuple).collect())
32 impl JoinView for CommunityBlockView {
33 type JoinTuple = CommunityBlockViewTuple;
34 fn from_tuple(a: Self::JoinTuple) -> Self {