mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
41 lines
772 B
Ruby
41 lines
772 B
Ruby
# frozen_string_literal: true
|
|
|
|
# API Controller for resources of type Order
|
|
# Orders are used in store
|
|
class API::OrdersController < API::ApiController
|
|
before_action :authenticate_user!
|
|
before_action :set_order, only: %i[show update destroy]
|
|
|
|
def index
|
|
@result = ::Orders::OrderService.list(params, current_user)
|
|
end
|
|
|
|
def show; end
|
|
|
|
def update
|
|
authorize @order
|
|
|
|
if @order.update(order_parameters)
|
|
render status: :ok
|
|
else
|
|
render json: @order.errors.full_messages, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
authorize @order
|
|
@order.destroy
|
|
head :no_content
|
|
end
|
|
|
|
private
|
|
|
|
def set_order
|
|
@order = Order.find(params[:id])
|
|
end
|
|
|
|
def order_params
|
|
params.require(:order).permit(:state)
|
|
end
|
|
end
|