2023-09-05 09:33:46 +00:00
|
|
|
use actix_web::web::{Data, Json, Query};
|
2022-04-13 18:12:25 +00:00
|
|
|
use lemmy_api_common::{
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2022-04-13 18:12:25 +00:00
|
|
|
post::{ListPostReports, ListPostReportsResponse},
|
2023-11-21 15:33:49 +00:00
|
|
|
utils::check_community_mod_of_any_or_admin_action,
|
2022-04-13 18:12:25 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView};
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
/// Lists post reports for a community if an id is supplied
|
|
|
|
/// or returns all post reports for communities a user moderates
|
2023-09-05 09:33:46 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn list_post_reports(
|
|
|
|
data: Query<ListPostReports>,
|
|
|
|
context: Data<LemmyContext>,
|
2023-09-21 10:42:28 +00:00
|
|
|
local_user_view: LocalUserView,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Json<ListPostReportsResponse>> {
|
2023-09-05 09:33:46 +00:00
|
|
|
let community_id = data.community_id;
|
2024-03-05 10:31:40 +00:00
|
|
|
let post_id = data.post_id;
|
2023-09-05 09:33:46 +00:00
|
|
|
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-11-21 15:33:49 +00:00
|
|
|
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
2023-10-13 13:48:18 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
let page = data.page;
|
|
|
|
let limit = data.limit;
|
|
|
|
let post_reports = PostReportQuery {
|
|
|
|
community_id,
|
2024-03-05 10:31:40 +00:00
|
|
|
post_id,
|
2023-09-05 09:33:46 +00:00
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|
2023-09-05 09:33:46 +00:00
|
|
|
.list(&mut context.pool(), &local_user_view)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(Json(ListPostReportsResponse { post_reports }))
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|