1 use diesel::{result::Error, *};
3 newtypes::{CommunityId, PersonId},
4 schema::{community, community_person_ban, person},
6 community::{Community, CommunitySafe},
7 person::{Person, PersonSafe},
11 use serde::{Deserialize, Serialize};
13 #[derive(Debug, Serialize, Deserialize, Clone)]
14 pub struct CommunityPersonBanView {
15 pub community: CommunitySafe,
16 pub person: PersonSafe,
19 impl CommunityPersonBanView {
22 from_person_id: PersonId,
23 from_community_id: CommunityId,
24 ) -> Result<Self, Error> {
25 let (community, person) = community_person_ban::table
26 .inner_join(community::table)
27 .inner_join(person::table)
29 Community::safe_columns_tuple(),
30 Person::safe_columns_tuple(),
32 .filter(community_person_ban::community_id.eq(from_community_id))
33 .filter(community_person_ban::person_id.eq(from_person_id))
34 .order_by(community_person_ban::published)
35 .first::<(CommunitySafe, PersonSafe)>(conn)?;
37 Ok(CommunityPersonBanView { community, person })