2023-07-28 14:39:38 +00:00
|
|
|
use actix_web::web::{Data, Json, Query};
|
2022-04-13 18:12:25 +00:00
|
|
|
use lemmy_api_common::{
|
|
|
|
comment::{ListCommentReports, ListCommentReportsResponse},
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::local_user_view_from_jwt,
|
2022-04-13 18:12:25 +00:00
|
|
|
};
|
2022-08-04 19:30:17 +00:00
|
|
|
use lemmy_db_views::comment_report_view::CommentReportQuery;
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
/// Lists comment reports for a community if an id is supplied
|
|
|
|
/// or returns all comment reports for communities a user moderates
|
2023-07-28 14:39:38 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn list_comment_reports(
|
|
|
|
data: Query<ListCommentReports>,
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
) -> Result<Json<ListCommentReportsResponse>, LemmyError> {
|
|
|
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-07-28 14:39:38 +00:00
|
|
|
let community_id = data.community_id;
|
2023-08-11 09:13:14 +00:00
|
|
|
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-07-28 14:39:38 +00:00
|
|
|
let page = data.page;
|
|
|
|
let limit = data.limit;
|
|
|
|
let comment_reports = CommentReportQuery {
|
|
|
|
community_id,
|
|
|
|
unresolved_only,
|
|
|
|
page,
|
|
|
|
limit,
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|
2023-08-24 09:40:08 +00:00
|
|
|
.list(&mut context.pool(), &local_user_view)
|
2023-07-28 14:39:38 +00:00
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(Json(ListCommentReportsResponse { comment_reports }))
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|