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

52 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).where(deleted_at: nil)
2016-05-04 18:17:50 +02:00
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
head :not_found if @machine.deleted_at
end
def destroy
method = @machine.destroyable? ? :destroy : :soft_destroy!
@machine.send(method)
head :no_content
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