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
24 async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
25 let conn = &mut get_conn(pool).await?;
26 insert_into(comment_report)
27 .values(comment_report_form)
28 .get_result::<Self>(conn)
32 /// resolve a comment report
34 /// * `conn` - the postgres connection
35 /// * `report_id` - the id of the report to resolve
36 /// * `by_resolver_id` - the id of the user resolving the report
39 report_id_: Self::IdType,
40 by_resolver_id: PersonId,
41 ) -> Result<usize, Error> {
42 let conn = &mut get_conn(pool).await?;
43 update(comment_report.find(report_id_))
46 resolver_id.eq(by_resolver_id),
47 updated.eq(naive_now()),
53 /// unresolve a comment report
55 /// * `conn` - the postgres connection
56 /// * `report_id` - the id of the report to unresolve
57 /// * `by_resolver_id` - the id of the user unresolving the report
60 report_id_: Self::IdType,
61 by_resolver_id: PersonId,
62 ) -> Result<usize, Error> {
63 let conn = &mut get_conn(pool).await?;
64 update(comment_report.find(report_id_))
67 resolver_id.eq(by_resolver_id),
68 updated.eq(naive_now()),