2 newtypes::{CommentReportId, PersonId},
3 source::comment_report::{CommentReport, CommentReportForm},
7 use diesel::{dsl::*, result::Error, *};
9 impl Reportable for CommentReport {
10 type Form = CommentReportForm;
11 type IdType = CommentReportId;
12 /// creates a comment report and returns it
14 /// * `conn` - the postgres connection
15 /// * `comment_report_form` - the filled CommentReportForm to insert
16 fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
17 use crate::schema::comment_report::dsl::*;
18 insert_into(comment_report)
19 .values(comment_report_form)
20 .get_result::<Self>(conn)
23 /// resolve a comment report
25 /// * `conn` - the postgres connection
26 /// * `report_id` - the id of the report to resolve
27 /// * `by_resolver_id` - the id of the user resolving the report
30 report_id: Self::IdType,
31 by_resolver_id: PersonId,
32 ) -> Result<usize, Error> {
33 use crate::schema::comment_report::dsl::*;
34 update(comment_report.find(report_id))
37 resolver_id.eq(by_resolver_id),
38 updated.eq(naive_now()),
43 /// unresolve a comment report
45 /// * `conn` - the postgres connection
46 /// * `report_id` - the id of the report to unresolve
47 /// * `by_resolver_id` - the id of the user unresolving the report
50 report_id: Self::IdType,
51 by_resolver_id: PersonId,
52 ) -> Result<usize, Error> {
53 use crate::schema::comment_report::dsl::*;
54 update(comment_report.find(report_id))
57 resolver_id.eq(by_resolver_id),
58 updated.eq(naive_now()),