mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-28 05:41:34 +00:00
15930cbf4d
* Update utils.rs * Update traits.rs * Update comment_report_view.rs * Update comment_view.rs * Update local_user_view.rs * Update post_report_view.rs * Update post_view.rs * Update private_message_report_view.rs * Update private_message_view.rs * Update registration_application_view.rs * Update site_view.rs * Update structs.rs * Update comment_reply_view.rs * Update community_block_view.rs * Update community_follower_view.rs * Update community_moderator_view.rs * Update community_person_ban_view.rs * Update community_person_ban_view.rs * Update community_view.rs * Update person_block_view.rs * Update person_mention_view.rs * Update person_view.rs * Update structs.rs * Update admin_purge_comment_view.rs * Update admin_purge_community_view.rs * Update admin_purge_person_view.rs * Update admin_purge_post_view.rs * Update mod_add_community_view.rs * Update mod_add_view.rs * Update mod_ban_from_community_view.rs * Update mod_ban_view.rs * Update mod_feature_post_view.rs * Update mod_hide_community_view.rs * Update mod_lock_post_view.rs * Update mod_remove_comment_view.rs * Update mod_remove_community_view.rs * Update mod_remove_post_view.rs * Update mod_transfer_community_view.rs * Update structs.rs * Update utils.rs * Update private_message_view.rs * Update comment_report_view.rs * Update registration_application_view.rs * Update utils.rs * fix * fix db_views * fix * Update comment_view.rs
30 lines
1 KiB
Rust
30 lines
1 KiB
Rust
use crate::structs::PersonBlockView;
|
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
|
use diesel_async::RunQueryDsl;
|
|
use lemmy_db_schema::{
|
|
newtypes::PersonId,
|
|
schema::{person, person_block},
|
|
utils::{get_conn, DbPool},
|
|
};
|
|
|
|
impl PersonBlockView {
|
|
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
let target_person_alias = diesel::alias!(person as person1);
|
|
|
|
person_block::table
|
|
.inner_join(person::table.on(person_block::person_id.eq(person::id)))
|
|
.inner_join(
|
|
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
|
|
)
|
|
.select((
|
|
person::all_columns,
|
|
target_person_alias.fields(person::all_columns),
|
|
))
|
|
.filter(person_block::person_id.eq(person_id))
|
|
.filter(target_person_alias.field(person::deleted).eq(false))
|
|
.order_by(person_block::published)
|
|
.load::<PersonBlockView>(conn)
|
|
.await
|
|
}
|
|
}
|