2022-09-19 22:58:42 +00:00
|
|
|
use crate::{
|
|
|
|
newtypes::{PersonId, PrivateMessageReportId},
|
2022-11-19 04:33:54 +00:00
|
|
|
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
2022-09-19 22:58:42 +00:00
|
|
|
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
|
|
|
traits::Reportable,
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, naive_now, DbPool},
|
2022-09-19 22:58:42 +00:00
|
|
|
};
|
2022-11-19 04:33:54 +00:00
|
|
|
use diesel::{
|
|
|
|
dsl::{insert_into, update},
|
|
|
|
result::Error,
|
|
|
|
ExpressionMethods,
|
|
|
|
QueryDsl,
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2022-09-19 22:58:42 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2022-09-19 22:58:42 +00:00
|
|
|
impl Reportable for PrivateMessageReport {
|
|
|
|
type Form = PrivateMessageReportForm;
|
|
|
|
type IdType = PrivateMessageReportId;
|
2022-11-09 10:05:00 +00:00
|
|
|
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn report(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
pm_report_form: &PrivateMessageReportForm,
|
|
|
|
) -> 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
|
|
|
insert_into(private_message_report)
|
|
|
|
.values(pm_report_form)
|
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-09-19 22:58:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn resolve(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2022-09-19 22:58:42 +00:00
|
|
|
report_id: Self::IdType,
|
|
|
|
by_resolver_id: PersonId,
|
|
|
|
) -> Result<usize, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-09-19 22:58:42 +00:00
|
|
|
update(private_message_report.find(report_id))
|
|
|
|
.set((
|
|
|
|
resolved.eq(true),
|
|
|
|
resolver_id.eq(by_resolver_id),
|
|
|
|
updated.eq(naive_now()),
|
|
|
|
))
|
|
|
|
.execute(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-09-19 22:58:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn unresolve(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2022-09-19 22:58:42 +00:00
|
|
|
report_id: Self::IdType,
|
|
|
|
by_resolver_id: PersonId,
|
|
|
|
) -> Result<usize, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-09-19 22:58:42 +00:00
|
|
|
update(private_message_report.find(report_id))
|
|
|
|
.set((
|
|
|
|
resolved.eq(false),
|
|
|
|
resolver_id.eq(by_resolver_id),
|
|
|
|
updated.eq(naive_now()),
|
|
|
|
))
|
|
|
|
.execute(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-09-19 22:58:42 +00:00
|
|
|
}
|
|
|
|
}
|