lemmy/crates/api/src/private_message_report/resolve.rs
Nutomic 366d9d1e2e
Get rid of remaining Perform/SendActivity traits (fixes #3670) (#3926)
* Get rid of remaining Perform/SendActivity traits (fixes #3670)

* fix api tests

* ci
2023-09-05 05:33:46 -04:00

38 lines
1.3 KiB
Rust

use actix_web::web::{Data, Json};
use lemmy_api_common::{
context::LemmyContext,
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
utils::{is_admin, local_user_view_from_jwt},
};
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
use lemmy_db_views::structs::PrivateMessageReportView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
#[tracing::instrument(skip(context))]
pub async fn resolve_pm_report(
data: Json<ResolvePrivateMessageReport>,
context: Data<LemmyContext>,
) -> Result<Json<PrivateMessageReportResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
is_admin(&local_user_view)?;
let report_id = data.report_id;
let person_id = local_user_view.person.id;
if data.resolved {
PrivateMessageReport::resolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
} else {
PrivateMessageReport::unresolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
}
let private_message_report_view =
PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
Ok(Json(PrivateMessageReportResponse {
private_message_report_view,
}))
}