2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 build_response::build_post_response,
6 post::{FeaturePost, PostResponse},
9 check_community_deleted_or_removed,
12 local_user_view_from_jwt,
15 use lemmy_db_schema::{
17 moderator::{ModFeaturePost, ModFeaturePostForm},
18 post::{Post, PostUpdateForm},
23 use lemmy_utils::error::LemmyError;
25 #[async_trait::async_trait(?Send)]
26 impl Perform for FeaturePost {
27 type Response = PostResponse;
29 #[tracing::instrument(skip(context))]
30 async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
31 let data: &FeaturePost = self;
32 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
34 let post_id = data.post_id;
35 let orig_post = Post::read(&mut context.pool(), post_id).await?;
38 local_user_view.person.id,
39 orig_post.community_id,
43 check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
45 if data.feature_type == PostFeatureType::Community {
46 // Verify that only the mods can feature in community
49 local_user_view.person.id,
50 orig_post.community_id,
54 is_admin(&local_user_view)?;
58 let post_id = data.post_id;
59 let new_post: PostUpdateForm = if data.feature_type == PostFeatureType::Community {
60 PostUpdateForm::builder()
61 .featured_community(Some(data.featured))
64 PostUpdateForm::builder()
65 .featured_local(Some(data.featured))
68 Post::update(&mut context.pool(), post_id, &new_post).await?;
71 let form = ModFeaturePostForm {
72 mod_person_id: local_user_view.person.id,
73 post_id: data.post_id,
74 featured: data.featured,
75 is_featured_community: data.feature_type == PostFeatureType::Community,
78 ModFeaturePost::create(&mut context.pool(), &form).await?;
82 orig_post.community_id,
83 local_user_view.person.id,