lists_controller.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # frozen_string_literal: true
  2. class Api::V1::ListsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:index, :show]
  4. before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:index, :show]
  5. before_action :require_user!
  6. before_action :set_list, except: [:index, :create]
  7. rescue_from ArgumentError do |e|
  8. render json: { error: e.to_s }, status: 422
  9. end
  10. def index
  11. @lists = List.where(account: current_account).all
  12. render json: @lists, each_serializer: REST::ListSerializer
  13. end
  14. def show
  15. render json: @list, serializer: REST::ListSerializer
  16. end
  17. def create
  18. @list = List.create!(list_params.merge(account: current_account))
  19. render json: @list, serializer: REST::ListSerializer
  20. end
  21. def update
  22. @list.update!(list_params)
  23. render json: @list, serializer: REST::ListSerializer
  24. end
  25. def destroy
  26. @list.destroy!
  27. render_empty
  28. end
  29. private
  30. def set_list
  31. @list = List.where(account: current_account).find(params[:id])
  32. end
  33. def list_params
  34. params.permit(:title, :replies_policy, :exclusive)
  35. end
  36. end