mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-12 04:55:55 +00:00
d075acce43
- Diesel ordinarily throws an error when no results are returned for a single fetch, which is a bit confusing. This PR ensures that the missing value cases are all caught, and wrapped with new LemmyErrors, rather than diesel errors. - Fixes #4601
38 lines
1.3 KiB
Rust
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,
|
|
};
|
|
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
|
|
use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView};
|
|
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn resolve_pm_report(
|
|
data: Json<ResolvePrivateMessageReport>,
|
|
context: Data<LemmyContext>,
|
|
local_user_view: LocalUserView,
|
|
) -> LemmyResult<Json<PrivateMessageReportResponse>> {
|
|
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_or(LemmyErrorType::CouldntFindPrivateMessageReport)?;
|
|
|
|
Ok(Json(PrivateMessageReportResponse {
|
|
private_message_report_view,
|
|
}))
|
|
}
|