2 newtypes::{CommentId, CommentReportId, PersonId},
3 schema::comment_report::{
5 dsl::{comment_report, resolved, resolver_id, updated},
7 source::comment_report::{CommentReport, CommentReportForm},
9 utils::{get_conn, naive_now, DbPool},
12 dsl::{insert_into, update},
17 use diesel_async::RunQueryDsl;
20 impl Reportable for CommentReport {
21 type Form = CommentReportForm;
22 type IdType = CommentReportId;
23 type ObjectIdType = CommentId;
24 /// creates a comment report and returns it
26 /// * `conn` - the postgres connection
27 /// * `comment_report_form` - the filled CommentReportForm to insert
29 pool: &mut DbPool<'_>,
30 comment_report_form: &CommentReportForm,
31 ) -> Result<Self, Error> {
32 let conn = &mut get_conn(pool).await?;
33 insert_into(comment_report)
34 .values(comment_report_form)
35 .get_result::<Self>(conn)
39 /// resolve a comment report
41 /// * `conn` - the postgres connection
42 /// * `report_id` - the id of the report to resolve
43 /// * `by_resolver_id` - the id of the user resolving the report
45 pool: &mut DbPool<'_>,
46 report_id_: Self::IdType,
47 by_resolver_id: PersonId,
48 ) -> Result<usize, Error> {
49 let conn = &mut get_conn(pool).await?;
50 update(comment_report.find(report_id_))
53 resolver_id.eq(by_resolver_id),
54 updated.eq(naive_now()),
60 async fn resolve_all_for_object(
61 pool: &mut DbPool<'_>,
62 comment_id_: CommentId,
63 by_resolver_id: PersonId,
64 ) -> Result<usize, Error> {
65 let conn = &mut get_conn(pool).await?;
66 update(comment_report.filter(comment_id.eq(comment_id_)))
69 resolver_id.eq(by_resolver_id),
70 updated.eq(naive_now()),
76 /// unresolve a comment report
78 /// * `conn` - the postgres connection
79 /// * `report_id` - the id of the report to unresolve
80 /// * `by_resolver_id` - the id of the user unresolving the report
82 pool: &mut DbPool<'_>,
83 report_id_: Self::IdType,
84 by_resolver_id: PersonId,
85 ) -> Result<usize, Error> {
86 let conn = &mut get_conn(pool).await?;
87 update(comment_report.find(report_id_))
90 resolver_id.eq(by_resolver_id),
91 updated.eq(naive_now()),