1 use diesel::{dsl::*, 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))
35 community_person_ban::expires
37 .or(community_person_ban::expires.gt(now)),
39 .order_by(community_person_ban::published)
40 .first::<(CommunitySafe, PersonSafe)>(conn)?;
42 Ok(CommunityPersonBanView { community, person })