2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{GetReportCount, GetReportCountResponse},
5 utils::{blocking, get_local_user_view_from_jwt},
7 use lemmy_db_views::structs::{CommentReportView, PostReportView};
8 use lemmy_utils::{error::LemmyError, ConnectionId};
9 use lemmy_websocket::LemmyContext;
11 #[async_trait::async_trait(?Send)]
12 impl Perform for GetReportCount {
13 type Response = GetReportCountResponse;
15 #[tracing::instrument(skip(context, _websocket_id))]
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<GetReportCountResponse, LemmyError> {
21 let data: &GetReportCount = self;
23 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
25 let person_id = local_user_view.person.id;
26 let admin = local_user_view.person.admin;
27 let community_id = data.community_id;
29 let comment_reports = blocking(context.pool(), move |conn| {
30 CommentReportView::get_report_count(conn, person_id, admin, community_id)
34 let post_reports = blocking(context.pool(), move |conn| {
35 PostReportView::get_report_count(conn, person_id, admin, community_id)
39 let res = GetReportCountResponse {