2021-10-16 13:33:38 +00:00
|
|
|
use crate::{
|
|
|
|
newtypes::{PersonId, PostReportId},
|
|
|
|
source::post_report::*,
|
|
|
|
traits::Reportable,
|
2022-05-03 17:44:13 +00:00
|
|
|
utils::naive_now,
|
2021-10-16 13:33:38 +00:00
|
|
|
};
|
2020-12-17 03:03:03 +00:00
|
|
|
use diesel::{dsl::*, result::Error, *};
|
|
|
|
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Reportable for PostReport {
|
|
|
|
type Form = PostReportForm;
|
2021-09-28 10:36:17 +00:00
|
|
|
type IdType = PostReportId;
|
|
|
|
|
2020-12-17 03:03:03 +00:00
|
|
|
/// creates a post report and returns it
|
|
|
|
///
|
|
|
|
/// * `conn` - the postgres connection
|
|
|
|
/// * `post_report_form` - the filled CommentReportForm to insert
|
2022-09-26 14:09:32 +00:00
|
|
|
fn report(conn: &mut PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
|
2021-10-16 13:33:38 +00:00
|
|
|
use crate::schema::post_report::dsl::*;
|
2020-12-17 03:03:03 +00:00
|
|
|
insert_into(post_report)
|
|
|
|
.values(post_report_form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// resolve a post report
|
|
|
|
///
|
|
|
|
/// * `conn` - the postgres connection
|
|
|
|
/// * `report_id` - the id of the report to resolve
|
|
|
|
/// * `by_resolver_id` - the id of the user resolving the report
|
2021-03-18 20:25:21 +00:00
|
|
|
fn resolve(
|
2022-09-26 14:09:32 +00:00
|
|
|
conn: &mut PgConnection,
|
2021-09-28 10:36:17 +00:00
|
|
|
report_id: Self::IdType,
|
2021-03-18 20:25:21 +00:00
|
|
|
by_resolver_id: PersonId,
|
|
|
|
) -> Result<usize, Error> {
|
2021-10-16 13:33:38 +00:00
|
|
|
use crate::schema::post_report::dsl::*;
|
2020-12-17 03:03:03 +00:00
|
|
|
update(post_report.find(report_id))
|
|
|
|
.set((
|
|
|
|
resolved.eq(true),
|
|
|
|
resolver_id.eq(by_resolver_id),
|
|
|
|
updated.eq(naive_now()),
|
|
|
|
))
|
|
|
|
.execute(conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// resolve a post report
|
|
|
|
///
|
|
|
|
/// * `conn` - the postgres connection
|
|
|
|
/// * `report_id` - the id of the report to unresolve
|
|
|
|
/// * `by_resolver_id` - the id of the user unresolving the report
|
2021-03-18 20:25:21 +00:00
|
|
|
fn unresolve(
|
2022-09-26 14:09:32 +00:00
|
|
|
conn: &mut PgConnection,
|
2021-09-28 10:36:17 +00:00
|
|
|
report_id: Self::IdType,
|
2021-03-18 20:25:21 +00:00
|
|
|
by_resolver_id: PersonId,
|
|
|
|
) -> Result<usize, Error> {
|
2021-10-16 13:33:38 +00:00
|
|
|
use crate::schema::post_report::dsl::*;
|
2020-12-17 03:03:03 +00:00
|
|
|
update(post_report.find(report_id))
|
|
|
|
.set((
|
|
|
|
resolved.eq(false),
|
|
|
|
resolver_id.eq(by_resolver_id),
|
|
|
|
updated.eq(naive_now()),
|
|
|
|
))
|
|
|
|
.execute(conn)
|
|
|
|
}
|
|
|
|
}
|