]> Untitled Git - lemmy.git/blob - crates/api/src/local_user/list_banned.rs
Split apart api files (#2216)
[lemmy.git] / crates / api / src / local_user / list_banned.rs
1 use crate::Perform;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4   blocking,
5   get_local_user_view_from_jwt,
6   is_admin,
7   person::{BannedPersonsResponse, GetBannedPersons},
8 };
9 use lemmy_db_views_actor::person_view::PersonViewSafe;
10 use lemmy_utils::{ConnectionId, LemmyError};
11 use lemmy_websocket::LemmyContext;
12
13 #[async_trait::async_trait(?Send)]
14 impl Perform for GetBannedPersons {
15   type Response = BannedPersonsResponse;
16
17   async fn perform(
18     &self,
19     context: &Data<LemmyContext>,
20     _websocket_id: Option<ConnectionId>,
21   ) -> Result<Self::Response, LemmyError> {
22     let data: &GetBannedPersons = self;
23     let local_user_view =
24       get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
25
26     // Make sure user is an admin
27     is_admin(&local_user_view)?;
28
29     let banned = blocking(context.pool(), PersonViewSafe::banned).await??;
30
31     let res = Self::Response { banned };
32
33     Ok(res)
34   }
35 }