logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

lists_controller.rb (1001B)


  1. # frozen_string_literal: true
  2. class Api::V1::ListsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read }, only: [:index, :show]
  4. before_action -> { doorkeeper_authorize! :write }, 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)
  32. end
  33. end