1 use crate::structs::CommunityPersonBanView;
2 use diesel::{dsl::*, result::Error, *};
4 newtypes::{CommunityId, PersonId},
5 schema::{community, community_person_ban, person},
7 community::{Community, CommunitySafe},
8 person::{Person, PersonSafe},
13 impl CommunityPersonBanView {
16 from_person_id: PersonId,
17 from_community_id: CommunityId,
18 ) -> Result<Self, Error> {
19 let (community, person) = community_person_ban::table
20 .inner_join(community::table)
21 .inner_join(person::table)
23 Community::safe_columns_tuple(),
24 Person::safe_columns_tuple(),
26 .filter(community_person_ban::community_id.eq(from_community_id))
27 .filter(community_person_ban::person_id.eq(from_person_id))
29 community_person_ban::expires
31 .or(community_person_ban::expires.gt(now)),
33 .order_by(community_person_ban::published)
34 .first::<(CommunitySafe, PersonSafe)>(conn)?;
36 Ok(CommunityPersonBanView { community, person })