The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
1.0 KiB

  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 = current_account.featured_tags.new(featured_tag_params)
  13. @featured_tag.reset_data
  14. @featured_tag.save!
  15. render json: @featured_tag, serializer: REST::FeaturedTagSerializer
  16. end
  17. def destroy
  18. @featured_tag.destroy!
  19. render_empty
  20. end
  21. private
  22. def set_featured_tag
  23. @featured_tag = current_account.featured_tags.find(params[:id])
  24. end
  25. def set_featured_tags
  26. @featured_tags = current_account.featured_tags.order(statuses_count: :desc)
  27. end
  28. def featured_tag_params
  29. params.permit(:name)
  30. end
  31. end