2022-09-19 22:58:42 +00:00
|
|
|
use crate::structs::PrivateMessageReportView;
|
2024-12-19 22:22:31 +00:00
|
|
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2022-09-19 22:58:42 +00:00
|
|
|
use lemmy_db_schema::{
|
2023-07-28 08:36:50 +00:00
|
|
|
aliases,
|
2022-09-19 22:58:42 +00:00
|
|
|
newtypes::PrivateMessageReportId,
|
2022-09-26 14:09:32 +00:00
|
|
|
schema::{person, private_message, private_message_report},
|
2024-12-19 22:22:31 +00:00
|
|
|
utils::{get_conn, DbPool},
|
2022-09-19 22:58:42 +00:00
|
|
|
};
|
|
|
|
|
2023-07-28 08:36:50 +00:00
|
|
|
impl PrivateMessageReportView {
|
|
|
|
/// returns the PrivateMessageReportView for the provided report_id
|
|
|
|
///
|
|
|
|
/// * `report_id` - the report id to obtain
|
|
|
|
pub async fn read(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
report_id: PrivateMessageReportId,
|
2024-09-23 15:26:50 +00:00
|
|
|
) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-09-19 22:58:42 +00:00
|
|
|
private_message_report::table
|
2024-12-19 22:22:31 +00:00
|
|
|
.find(report_id)
|
2022-09-19 22:58:42 +00:00
|
|
|
.inner_join(private_message::table)
|
2024-12-19 22:22:31 +00:00
|
|
|
.inner_join(person::table.on(private_message::creator_id.eq(person::id)))
|
|
|
|
.inner_join(
|
|
|
|
aliases::person1
|
|
|
|
.on(private_message_report::creator_id.eq(aliases::person1.field(person::id))),
|
|
|
|
)
|
|
|
|
.left_join(
|
|
|
|
aliases::person2.on(
|
|
|
|
private_message_report::resolver_id.eq(aliases::person2.field(person::id).nullable()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.select((
|
|
|
|
private_message_report::all_columns,
|
|
|
|
private_message::all_columns,
|
|
|
|
person::all_columns,
|
|
|
|
aliases::person1.fields(person::all_columns),
|
|
|
|
aliases::person2.fields(person::all_columns).nullable(),
|
|
|
|
))
|
|
|
|
.first(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-09-19 22:58:42 +00:00
|
|
|
}
|
|
|
|
}
|