2022-09-12 19:44:13 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Order
|
|
|
|
# Orders are used in store
|
|
|
|
class API::OrdersController < API::ApiController
|
2022-10-13 17:57:26 +02:00
|
|
|
before_action :authenticate_user!, except: %i[withdrawal_instructions]
|
2022-10-13 11:23:35 +02:00
|
|
|
before_action :set_order, only: %i[show update destroy withdrawal_instructions]
|
2022-09-12 19:44:13 +02:00
|
|
|
|
|
|
|
def index
|
|
|
|
@result = ::Orders::OrderService.list(params, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show; end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize @order
|
|
|
|
|
2022-09-15 20:19:19 +02:00
|
|
|
@order = ::Orders::OrderService.update_state(@order, current_user, order_params[:state], order_params[:note])
|
|
|
|
render :show
|
2022-09-12 19:44:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize @order
|
|
|
|
@order.destroy
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
|
2022-10-05 12:06:35 +02:00
|
|
|
def withdrawal_instructions
|
2022-10-13 11:23:35 +02:00
|
|
|
authorize @order
|
|
|
|
|
|
|
|
render html: ::Orders::OrderService.withdrawal_instructions(@order)
|
2022-10-05 12:06:35 +02:00
|
|
|
end
|
|
|
|
|
2022-09-12 19:44:13 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_order
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def order_params
|
2022-09-15 20:19:19 +02:00
|
|
|
params.require(:order).permit(:state, :note)
|
2022-09-12 19:44:13 +02:00
|
|
|
end
|
|
|
|
end
|