2022-05-03 17:44:13 +00:00
|
|
|
use crate::structs::CommunityBlockView;
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
|
|
|
use diesel_async::RunQueryDsl;
|
2021-08-19 20:54:15 +00:00
|
|
|
use lemmy_db_schema::{
|
2021-10-16 13:33:38 +00:00
|
|
|
newtypes::PersonId,
|
2021-08-19 20:54:15 +00:00
|
|
|
schema::{community, community_block, person},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, DbPool},
|
2021-08-19 20:54:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
impl CommunityBlockView {
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-08-31 13:26:10 +00:00
|
|
|
community_block::table
|
2021-08-19 20:54:15 +00:00
|
|
|
.inner_join(person::table)
|
|
|
|
.inner_join(community::table)
|
2023-03-01 17:19:46 +00:00
|
|
|
.select((person::all_columns, community::all_columns))
|
2021-08-19 20:54:15 +00:00
|
|
|
.filter(community_block::person_id.eq(person_id))
|
2022-09-28 20:54:32 +00:00
|
|
|
.filter(community::deleted.eq(false))
|
|
|
|
.filter(community::removed.eq(false))
|
2021-08-19 20:54:15 +00:00
|
|
|
.order_by(community_block::published)
|
2023-08-31 13:26:10 +00:00
|
|
|
.load::<CommunityBlockView>(conn)
|
|
|
|
.await
|
2021-08-19 20:54:15 +00:00
|
|
|
}
|
|
|
|
}
|