2017-11-18 00:16:48 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::ListsController < Api::BaseController
|
2018-08-26 19:22:46 +02:00
|
|
|
before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:index, :show]
|
2018-07-05 18:31:35 +02:00
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:index, :show]
|
2017-11-18 00:16:48 +01:00
|
|
|
|
|
|
|
before_action :require_user!
|
|
|
|
before_action :set_list, except: [:index, :create]
|
|
|
|
|
2022-11-08 16:37:28 +01:00
|
|
|
rescue_from ArgumentError do |e|
|
|
|
|
render json: { error: e.to_s }, status: 422
|
|
|
|
end
|
|
|
|
|
2017-11-18 00:16:48 +01:00
|
|
|
def index
|
2017-12-09 01:32:29 +01:00
|
|
|
@lists = List.where(account: current_account).all
|
2017-11-18 00:16:48 +01:00
|
|
|
render json: @lists, each_serializer: REST::ListSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
render json: @list, serializer: REST::ListSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@list = List.create!(list_params.merge(account: current_account))
|
|
|
|
render json: @list, serializer: REST::ListSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@list.update!(list_params)
|
|
|
|
render json: @list, serializer: REST::ListSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@list.destroy!
|
|
|
|
render_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_list
|
|
|
|
@list = List.where(account: current_account).find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_params
|
2023-06-05 09:37:02 +02:00
|
|
|
params.permit(:title, :replies_policy, :exclusive)
|
2017-11-18 00:16:48 +01:00
|
|
|
end
|
|
|
|
end
|