about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/v1/featured_tags_controller.rb8
-rw-r--r--app/controllers/settings/featured_tags_controller.rb13
2 files changed, 10 insertions, 11 deletions
diff --git a/app/controllers/api/v1/featured_tags_controller.rb b/app/controllers/api/v1/featured_tags_controller.rb
index a67db7040..edb42a94e 100644
--- a/app/controllers/api/v1/featured_tags_controller.rb
+++ b/app/controllers/api/v1/featured_tags_controller.rb
@@ -13,14 +13,12 @@ class Api::V1::FeaturedTagsController < Api::BaseController
   end
 
   def create
-    @featured_tag = current_account.featured_tags.create!(featured_tag_params)
-    ActivityPub::UpdateDistributionWorker.perform_in(3.minutes, current_account.id)
-    render json: @featured_tag, serializer: REST::FeaturedTagSerializer
+    featured_tag = CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name])
+    render json: featured_tag, serializer: REST::FeaturedTagSerializer
   end
 
   def destroy
-    @featured_tag.destroy!
-    ActivityPub::UpdateDistributionWorker.perform_in(3.minutes, current_account.id)
+    RemoveFeaturedTagWorker.perform_async(current_account.id, @featured_tag.id)
     render_empty
   end
 
diff --git a/app/controllers/settings/featured_tags_controller.rb b/app/controllers/settings/featured_tags_controller.rb
index ae714e912..cc6ec0843 100644
--- a/app/controllers/settings/featured_tags_controller.rb
+++ b/app/controllers/settings/featured_tags_controller.rb
@@ -10,10 +10,8 @@ class Settings::FeaturedTagsController < Settings::BaseController
   end
 
   def create
-    @featured_tag = current_account.featured_tags.new(featured_tag_params)
-
-    if @featured_tag.save
-      ActivityPub::UpdateDistributionWorker.perform_in(3.minutes, current_account.id)
+    if !featured_tag_exists?
+      CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name])
       redirect_to settings_featured_tags_path
     else
       set_featured_tags
@@ -24,13 +22,16 @@ class Settings::FeaturedTagsController < Settings::BaseController
   end
 
   def destroy
-    @featured_tag.destroy!
-    ActivityPub::UpdateDistributionWorker.perform_in(3.minutes, current_account.id)
+    RemoveFeaturedTagWorker.perform_async(current_account.id, @featured_tag.id)
     redirect_to settings_featured_tags_path
   end
 
   private
 
+  def featured_tag_exists?
+    current_account.featured_tags.by_name(featured_tag_params[:name]).exists?
+  end
+
   def set_featured_tag
     @featured_tag = current_account.featured_tags.find(params[:id])
   end