featured_tags_controller.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. class Api::V1::FeaturedTagsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:accounts' }, only: :index
  4. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, except: :index
  5. before_action :require_user!
  6. before_action :set_featured_tags, only: :index
  7. before_action :set_featured_tag, except: [:index, :create]
  8. def index
  9. render json: @featured_tags, each_serializer: REST::FeaturedTagSerializer
  10. end
  11. def create
  12. featured_tag = CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name])
  13. render json: featured_tag, serializer: REST::FeaturedTagSerializer
  14. end
  15. def destroy
  16. RemoveFeaturedTagWorker.perform_async(current_account.id, @featured_tag.id)
  17. render_empty
  18. end
  19. private
  20. def set_featured_tag
  21. @featured_tag = current_account.featured_tags.find(params[:id])
  22. end
  23. def set_featured_tags
  24. @featured_tags = current_account.featured_tags.order(statuses_count: :desc)
  25. end
  26. def featured_tag_params
  27. params.permit(:name)
  28. end
  29. end