X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_schema%2Fsrc%2Fimpls%2Fcomment_report.rs;h=19c12876f7679d8523060a78d7e1665b2b7587a9;hb=f7f6766650b9b573a72075e564aed353c0131cd7;hp=18cf83a72f74d97da8635aa305adba96198aee1e;hpb=6f3bf4634b0e1cf529c4683d6ee971917e2bfa50;p=lemmy.git diff --git a/crates/db_schema/src/impls/comment_report.rs b/crates/db_schema/src/impls/comment_report.rs index 18cf83a7..19c12876 100644 --- a/crates/db_schema/src/impls/comment_report.rs +++ b/crates/db_schema/src/impls/comment_report.rs @@ -1,6 +1,9 @@ use crate::{ - newtypes::{CommentReportId, PersonId}, - schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated}, + newtypes::{CommentId, CommentReportId, PersonId}, + schema::comment_report::{ + comment_id, + dsl::{comment_report, resolved, resolver_id, updated}, + }, source::comment_report::{CommentReport, CommentReportForm}, traits::Reportable, utils::{get_conn, naive_now, DbPool}, @@ -17,11 +20,15 @@ use diesel_async::RunQueryDsl; impl Reportable for CommentReport { type Form = CommentReportForm; type IdType = CommentReportId; + type ObjectIdType = CommentId; /// creates a comment report and returns it /// /// * `conn` - the postgres connection /// * `comment_report_form` - the filled CommentReportForm to insert - async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result { + async fn report( + pool: &mut DbPool<'_>, + comment_report_form: &CommentReportForm, + ) -> Result { let conn = &mut get_conn(pool).await?; insert_into(comment_report) .values(comment_report_form) @@ -35,7 +42,7 @@ impl Reportable for CommentReport { /// * `report_id` - the id of the report to resolve /// * `by_resolver_id` - the id of the user resolving the report async fn resolve( - pool: &DbPool, + pool: &mut DbPool<'_>, report_id_: Self::IdType, by_resolver_id: PersonId, ) -> Result { @@ -50,13 +57,29 @@ impl Reportable for CommentReport { .await } + async fn resolve_all_for_object( + pool: &mut DbPool<'_>, + comment_id_: CommentId, + by_resolver_id: PersonId, + ) -> Result { + let conn = &mut get_conn(pool).await?; + update(comment_report.filter(comment_id.eq(comment_id_))) + .set(( + resolved.eq(true), + resolver_id.eq(by_resolver_id), + updated.eq(naive_now()), + )) + .execute(conn) + .await + } + /// unresolve a comment report /// /// * `conn` - the postgres connection /// * `report_id` - the id of the report to unresolve /// * `by_resolver_id` - the id of the user unresolving the report async fn unresolve( - pool: &DbPool, + pool: &mut DbPool<'_>, report_id_: Self::IdType, by_resolver_id: PersonId, ) -> Result {