2 newtypes::{CommentReportId, PersonId},
3 schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
4 source::comment_report::{CommentReport, CommentReportForm},
6 utils::{get_conn, naive_now, DbPool},
9 dsl::{insert_into, update},
14 use diesel_async::RunQueryDsl;
17 impl Reportable for CommentReport {
18 type Form = CommentReportForm;
19 type IdType = CommentReportId;
20 /// creates a comment report and returns it
22 /// * `conn` - the postgres connection
23 /// * `comment_report_form` - the filled CommentReportForm to insert
25 pool: &mut DbPool<'_>,
26 comment_report_form: &CommentReportForm,
27 ) -> Result<Self, Error> {
28 let conn = &mut get_conn(pool).await?;
29 insert_into(comment_report)
30 .values(comment_report_form)
31 .get_result::<Self>(conn)
35 /// resolve a comment report
37 /// * `conn` - the postgres connection
38 /// * `report_id` - the id of the report to resolve
39 /// * `by_resolver_id` - the id of the user resolving the report
41 pool: &mut DbPool<'_>,
42 report_id_: Self::IdType,
43 by_resolver_id: PersonId,
44 ) -> Result<usize, Error> {
45 let conn = &mut get_conn(pool).await?;
46 update(comment_report.find(report_id_))
49 resolver_id.eq(by_resolver_id),
50 updated.eq(naive_now()),
56 /// unresolve a comment report
58 /// * `conn` - the postgres connection
59 /// * `report_id` - the id of the report to unresolve
60 /// * `by_resolver_id` - the id of the user unresolving the report
62 pool: &mut DbPool<'_>,
63 report_id_: Self::IdType,
64 by_resolver_id: PersonId,
65 ) -> Result<usize, Error> {
66 let conn = &mut get_conn(pool).await?;
67 update(comment_report.find(report_id_))
70 resolver_id.eq(by_resolver_id),
71 updated.eq(naive_now()),