1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 build_response::build_community_response,
5 community::{CommunityResponse, DeleteCommunity},
7 utils::{is_top_mod, local_user_view_from_jwt},
10 source::community::{Community, CommunityUpdateForm},
13 use lemmy_db_views_actor::structs::CommunityModeratorView;
14 use lemmy_utils::error::LemmyError;
16 #[async_trait::async_trait(?Send)]
17 impl PerformCrud for DeleteCommunity {
18 type Response = CommunityResponse;
20 #[tracing::instrument(skip(context))]
21 async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
22 let data: &DeleteCommunity = self;
23 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
25 // Fetch the community mods
26 let community_id = data.community_id;
28 CommunityModeratorView::for_community(context.pool(), community_id).await?;
30 // Make sure deleter is the top mod
31 is_top_mod(&local_user_view, &community_mods)?;
34 let community_id = data.community_id;
35 let deleted = data.deleted;
39 &CommunityUpdateForm::builder()
40 .deleted(Some(deleted))
44 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
46 build_community_response(context, local_user_view, community_id).await