lists_controller.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. def index
  8. @lists = List.where(account: current_account).all
  9. render json: @lists, each_serializer: REST::ListSerializer
  10. end
  11. def show
  12. render json: @list, serializer: REST::ListSerializer
  13. end
  14. def create
  15. @list = List.create!(list_params.merge(account: current_account))
  16. render json: @list, serializer: REST::ListSerializer
  17. end
  18. def update
  19. @list.update!(list_params)
  20. render json: @list, serializer: REST::ListSerializer
  21. end
  22. def destroy
  23. @list.destroy!
  24. render_empty
  25. end
  26. private
  27. def set_list
  28. @list = List.where(account: current_account).find(params[:id])
  29. end
  30. def list_params
  31. params.permit(:title, :replies_policy)
  32. end
  33. end