]> Untitled Git - lemmy.git/blob - crates/api/src/comment_report/list.rs
Replace Option<bool> with bool for PostQuery and CommentQuery (#3819) (#3857)
[lemmy.git] / crates / api / src / comment_report / list.rs
1 use actix_web::web::{Data, Json, Query};
2 use lemmy_api_common::{
3   comment::{ListCommentReports, ListCommentReportsResponse},
4   context::LemmyContext,
5   utils::local_user_view_from_jwt,
6 };
7 use lemmy_db_views::comment_report_view::CommentReportQuery;
8 use lemmy_utils::error::LemmyError;
9
10 /// Lists comment reports for a community if an id is supplied
11 /// or returns all comment reports for communities a user moderates
12 #[tracing::instrument(skip(context))]
13 pub async fn list_comment_reports(
14   data: Query<ListCommentReports>,
15   context: Data<LemmyContext>,
16 ) -> Result<Json<ListCommentReportsResponse>, LemmyError> {
17   let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
18
19   let community_id = data.community_id;
20   let unresolved_only = data.unresolved_only.unwrap_or_default();
21
22   let page = data.page;
23   let limit = data.limit;
24   let comment_reports = CommentReportQuery {
25     community_id,
26     unresolved_only,
27     page,
28     limit,
29   }
30   .list(&mut context.pool(), &local_user_view.person)
31   .await?;
32
33   Ok(Json(ListCommentReportsResponse { comment_reports }))
34 }