mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-14 22:30:42 +00:00
50f81cf157
* User can block instances (fixes #2397) * update comments * review comments * use route * update * add api test * update tests * fix * fix test * ci --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
28 lines
906 B
Rust
28 lines
906 B
Rust
use crate::structs::InstanceBlockView;
|
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
|
use diesel_async::RunQueryDsl;
|
|
use lemmy_db_schema::{
|
|
newtypes::PersonId,
|
|
schema::{instance, instance_block, person, site},
|
|
utils::{get_conn, DbPool},
|
|
};
|
|
|
|
impl InstanceBlockView {
|
|
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
instance_block::table
|
|
.inner_join(person::table)
|
|
.inner_join(instance::table)
|
|
.left_join(site::table.on(site::instance_id.eq(instance::id)))
|
|
.select((
|
|
person::all_columns,
|
|
instance::all_columns,
|
|
site::all_columns.nullable(),
|
|
))
|
|
.filter(instance_block::person_id.eq(person_id))
|
|
.order_by(instance_block::published)
|
|
.load::<InstanceBlockView>(conn)
|
|
.await
|
|
}
|
|
}
|