2 newtypes::{PersonId, PostReportId},
3 source::post_report::*,
7 use diesel::{dsl::*, result::Error, *};
9 impl Reportable for PostReport {
10 type Form = PostReportForm;
11 type IdType = PostReportId;
13 /// creates a post report and returns it
15 /// * `conn` - the postgres connection
16 /// * `post_report_form` - the filled CommentReportForm to insert
17 fn report(conn: &mut PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
18 use crate::schema::post_report::dsl::*;
19 insert_into(post_report)
20 .values(post_report_form)
21 .get_result::<Self>(conn)
24 /// resolve a post report
26 /// * `conn` - the postgres connection
27 /// * `report_id` - the id of the report to resolve
28 /// * `by_resolver_id` - the id of the user resolving the report
30 conn: &mut PgConnection,
31 report_id: Self::IdType,
32 by_resolver_id: PersonId,
33 ) -> Result<usize, Error> {
34 use crate::schema::post_report::dsl::*;
35 update(post_report.find(report_id))
38 resolver_id.eq(by_resolver_id),
39 updated.eq(naive_now()),
44 /// resolve a post report
46 /// * `conn` - the postgres connection
47 /// * `report_id` - the id of the report to unresolve
48 /// * `by_resolver_id` - the id of the user unresolving the report
50 conn: &mut PgConnection,
51 report_id: Self::IdType,
52 by_resolver_id: PersonId,
53 ) -> Result<usize, Error> {
54 use crate::schema::post_report::dsl::*;
55 update(post_report.find(report_id))
58 resolver_id.eq(by_resolver_id),
59 updated.eq(naive_now()),