2 newtypes::{CommentReportId, PersonId},
3 schema::comment_report::dsl::*,
4 source::comment_report::{CommentReport, CommentReportForm},
6 utils::{get_conn, naive_now, DbPool},
8 use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
9 use diesel_async::RunQueryDsl;
12 impl Reportable for CommentReport {
13 type Form = CommentReportForm;
14 type IdType = CommentReportId;
15 /// creates a comment report and returns it
17 /// * `conn` - the postgres connection
18 /// * `comment_report_form` - the filled CommentReportForm to insert
19 async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
20 let conn = &mut get_conn(pool).await?;
21 insert_into(comment_report)
22 .values(comment_report_form)
23 .get_result::<Self>(conn)
27 /// resolve a comment report
29 /// * `conn` - the postgres connection
30 /// * `report_id` - the id of the report to resolve
31 /// * `by_resolver_id` - the id of the user resolving the report
34 report_id_: Self::IdType,
35 by_resolver_id: PersonId,
36 ) -> Result<usize, Error> {
37 let conn = &mut get_conn(pool).await?;
38 update(comment_report.find(report_id_))
41 resolver_id.eq(by_resolver_id),
42 updated.eq(naive_now()),
48 /// unresolve a comment report
50 /// * `conn` - the postgres connection
51 /// * `report_id` - the id of the report to unresolve
52 /// * `by_resolver_id` - the id of the user unresolving the report
55 report_id_: Self::IdType,
56 by_resolver_id: PersonId,
57 ) -> Result<usize, Error> {
58 let conn = &mut get_conn(pool).await?;
59 update(comment_report.find(report_id_))
62 resolver_id.eq(by_resolver_id),
63 updated.eq(naive_now()),