2022-09-19 22:58:42 +00:00
|
|
|
use crate::{
|
|
|
|
newtypes::{PersonId, PrivateMessageReportId},
|
2022-11-09 10:05:00 +00:00
|
|
|
schema::private_message_report::dsl::*,
|
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
|
|
|
};
|
|
|
|
use diesel::{dsl::*, result::Error, *};
|
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
|
|
|
|
|
|
|
async fn report(pool: &DbPool, pm_report_form: &PrivateMessageReportForm) -> Result<Self, Error> {
|
|
|
|
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(
|
|
|
|
pool: &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(
|
|
|
|
pool: &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
|
|
|
}
|
|
|
|
}
|