use crate::{
newtypes::{PersonId, PostReportId},
- source::post_report::*,
+ schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
+ source::post_report::{PostReport, PostReportForm},
traits::Reportable,
- utils::naive_now,
+ utils::{get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, *};
+use diesel::{
+ dsl::{insert_into, update},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
+use diesel_async::RunQueryDsl;
+#[async_trait]
impl Reportable for PostReport {
type Form = PostReportForm;
type IdType = PostReportId;
- /// creates a post report and returns it
- ///
- /// * `conn` - the postgres connection
- /// * `post_report_form` - the filled CommentReportForm to insert
- fn report(conn: &mut PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
- use crate::schema::post_report::dsl::*;
+ async fn report(pool: &mut DbPool<'_>, post_report_form: &PostReportForm) -> Result<Self, Error> {
+ let conn = &mut get_conn(pool).await?;
insert_into(post_report)
.values(post_report_form)
.get_result::<Self>(conn)
+ .await
}
- /// resolve a post report
- ///
- /// * `conn` - the postgres connection
- /// * `report_id` - the id of the report to resolve
- /// * `by_resolver_id` - the id of the user resolving the report
- fn resolve(
- conn: &mut PgConnection,
+ async fn resolve(
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
- use crate::schema::post_report::dsl::*;
+ let conn = &mut get_conn(pool).await?;
update(post_report.find(report_id))
.set((
resolved.eq(true),
updated.eq(naive_now()),
))
.execute(conn)
+ .await
}
- /// resolve a post 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
- fn unresolve(
- conn: &mut PgConnection,
+ async fn unresolve(
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
- use crate::schema::post_report::dsl::*;
+ let conn = &mut get_conn(pool).await?;
update(post_report.find(report_id))
.set((
resolved.eq(false),
updated.eq(naive_now()),
))
.execute(conn)
+ .await
}
}