mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-04-27 05:04:44 +00:00
* Remove explicit auth params (ref #3725) Only take auth via header or cookie. This requires a new version of lemmy-js-client for api tests to pass. * rework api_crud * remove remaining auth params, move logic to session middleware * fmt, fix test * update js client * remove auth param from api tests * Pass auth as header * add ! * url vars, setHeader * cleanup * fmt * update * Updating for new lemmy-js-client. --------- Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use actix_web::web::{Data, Json};
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
person::{GetReportCount, GetReportCountResponse},
|
|
};
|
|
use lemmy_db_views::structs::{
|
|
CommentReportView,
|
|
LocalUserView,
|
|
PostReportView,
|
|
PrivateMessageReportView,
|
|
};
|
|
use lemmy_utils::error::LemmyError;
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn report_count(
|
|
data: Json<GetReportCount>,
|
|
context: Data<LemmyContext>,
|
|
local_user_view: LocalUserView,
|
|
) -> Result<Json<GetReportCountResponse>, LemmyError> {
|
|
let person_id = local_user_view.person.id;
|
|
let admin = local_user_view.local_user.admin;
|
|
let community_id = data.community_id;
|
|
|
|
let comment_reports =
|
|
CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
|
|
.await?;
|
|
|
|
let post_reports =
|
|
PostReportView::get_report_count(&mut context.pool(), person_id, admin, community_id).await?;
|
|
|
|
let private_message_reports = if admin && community_id.is_none() {
|
|
Some(PrivateMessageReportView::get_report_count(&mut context.pool()).await?)
|
|
} else {
|
|
None
|
|
};
|
|
|
|
Ok(Json(GetReportCountResponse {
|
|
community_id,
|
|
comment_reports,
|
|
post_reports,
|
|
private_message_reports,
|
|
}))
|
|
}
|