2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
6 utils::{is_admin, local_user_view_from_jwt},
8 use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
9 use lemmy_db_views::structs::PrivateMessageReportView;
10 use lemmy_utils::error::LemmyError;
12 #[async_trait::async_trait(?Send)]
13 impl Perform for ResolvePrivateMessageReport {
14 type Response = PrivateMessageReportResponse;
16 #[tracing::instrument(skip(context))]
17 async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
18 let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
20 is_admin(&local_user_view)?;
22 let report_id = self.report_id;
23 let person_id = local_user_view.person.id;
25 PrivateMessageReport::resolve(context.pool(), report_id, person_id)
27 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
29 PrivateMessageReport::unresolve(context.pool(), report_id, person_id)
31 .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
34 let private_message_report_view =
35 PrivateMessageReportView::read(context.pool(), report_id).await?;
37 Ok(PrivateMessageReportResponse {
38 private_message_report_view,