1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/controllers/open_api/v1/machines_controller.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# authorized 3rd party softwares can manage the machines through the OpenAPI
2016-05-04 18:17:50 +02:00
class OpenAPI::V1::MachinesController < OpenAPI::V1::BaseController
2016-05-05 15:02:02 +02:00
extend OpenAPI::ApiDoc
expose_doc
before_action :set_machine, only: %i[show update destroy]
2016-05-04 18:17:50 +02:00
def index
@machines = Machine.order(:created_at)
end
def create
@machine = Machine.new(machine_params)
if @machine.save
render :show, status: :created, location: @machine
else
render json: @machine.errors, status: :unprocessable_entity
end
end
def update
if @machine.update(machine_params)
render :show, status: :ok, location: @machine
else
render json: @machine.errors, status: :unprocessable_entity
end
end
def show; end
def destroy
if @machine.destroyable?
@machine.destroy
head :no_content
else
render json: { error: 'has existing reservations' }, status: :unprocessable_entity
end
end
private
def machine_params
params.require(:machine).permit(:name, :description, :spec, :disabled,
machine_image_attributes: [:attachment])
end
def set_machine
@machine = Machine.friendly.find(params[:id])
end
2016-05-04 18:17:50 +02:00
end