mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-08 16:39:22 +00:00
c9f1407429
* Initial commit to bump diesel to 2.0.0-rc.0 and see what happens * Add chrono feature from diesel * db_schema crate is close to building? * Upgrade diesel-derive-newtype * Mostly modifying references to connections to be mutable ones; also used new way to do migrations as suggested by the migration guide; a lot more compiles now, though I can't figure out this tricky ToSql issue at the moment * Running clippy --fix * Trying to fix drone clippy 1 * Fix clippy * Upgrade clux-musl * Trying to fix drone clippy 2 * Trying to fix drone clippy 3 * Trying to fix drone clippy 5 * Adding diesel table aliases, removing sql view hack. Fixes #2101 Co-authored-by: Steven Chu <stevenc1@gmail.com> Co-authored-by: Nutomic <me@nutomic.com>
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use crate::structs::CommunityPersonBanView;
|
|
use diesel::{dsl::*, result::Error, *};
|
|
use lemmy_db_schema::{
|
|
newtypes::{CommunityId, PersonId},
|
|
schema::{community, community_person_ban, person},
|
|
source::{
|
|
community::{Community, CommunitySafe},
|
|
person::{Person, PersonSafe},
|
|
},
|
|
traits::ToSafe,
|
|
};
|
|
|
|
impl CommunityPersonBanView {
|
|
pub fn get(
|
|
conn: &mut PgConnection,
|
|
from_person_id: PersonId,
|
|
from_community_id: CommunityId,
|
|
) -> Result<Self, Error> {
|
|
let (community, person) = community_person_ban::table
|
|
.inner_join(community::table)
|
|
.inner_join(person::table)
|
|
.select((
|
|
Community::safe_columns_tuple(),
|
|
Person::safe_columns_tuple(),
|
|
))
|
|
.filter(community_person_ban::community_id.eq(from_community_id))
|
|
.filter(community_person_ban::person_id.eq(from_person_id))
|
|
.filter(
|
|
community_person_ban::expires
|
|
.is_null()
|
|
.or(community_person_ban::expires.gt(now)),
|
|
)
|
|
.order_by(community_person_ban::published)
|
|
.first::<(CommunitySafe, PersonSafe)>(conn)?;
|
|
|
|
Ok(CommunityPersonBanView { community, person })
|
|
}
|
|
}
|