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.
 
 
 
 

49 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::FiltersController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:filters' }, only: [:index, :show]
  4. before_action -> { doorkeeper_authorize! :write, :'write:filters' }, except: [:index, :show]
  5. before_action :require_user!
  6. before_action :set_filters, only: :index
  7. before_action :set_filter, only: [:show, :update, :destroy]
  8. respond_to :json
  9. def index
  10. render json: @filters, each_serializer: REST::FilterSerializer
  11. end
  12. def create
  13. @filter = current_account.custom_filters.create!(resource_params)
  14. render json: @filter, serializer: REST::FilterSerializer
  15. end
  16. def show
  17. render json: @filter, serializer: REST::FilterSerializer
  18. end
  19. def update
  20. @filter.update!(resource_params)
  21. render json: @filter, serializer: REST::FilterSerializer
  22. end
  23. def destroy
  24. @filter.destroy!
  25. render_empty
  26. end
  27. private
  28. def set_filters
  29. @filters = current_account.custom_filters
  30. end
  31. def set_filter
  32. @filter = current_account.custom_filters.find(params[:id])
  33. end
  34. def resource_params
  35. params.permit(:phrase, :expires_in, :irreversible, :whole_word, context: [])
  36. end
  37. end