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
17 conn: &mut PgConnection,
18 comment_report_form: &CommentReportForm,
19 ) -> Result<Self, Error> {
20 use crate::schema::comment_report::dsl::*;
21 insert_into(comment_report)
22 .values(comment_report_form)
23 .get_result::<Self>(conn)
26 /// resolve a comment report
28 /// * `conn` - the postgres connection
29 /// * `report_id` - the id of the report to resolve
30 /// * `by_resolver_id` - the id of the user resolving the report
32 conn: &mut PgConnection,
33 report_id: Self::IdType,
34 by_resolver_id: PersonId,
35 ) -> Result<usize, Error> {
36 use crate::schema::comment_report::dsl::*;
37 update(comment_report.find(report_id))
40 resolver_id.eq(by_resolver_id),
41 updated.eq(naive_now()),
46 /// unresolve a comment report
48 /// * `conn` - the postgres connection
49 /// * `report_id` - the id of the report to unresolve
50 /// * `by_resolver_id` - the id of the user unresolving the report
52 conn: &mut PgConnection,
53 report_id: Self::IdType,
54 by_resolver_id: PersonId,
55 ) -> Result<usize, Error> {
56 use crate::schema::comment_report::dsl::*;
57 update(comment_report.find(report_id))
60 resolver_id.eq(by_resolver_id),
61 updated.eq(naive_now()),