mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-10 21:24:20 +01:00
0cd841da33
TODO: - events controller - availabilies controller - members controller - plans controller
50 lines
1.1 KiB
Ruby
50 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# API Controller for resources of type Component
|
|
# Components are used in Projects
|
|
class API::ComponentsController < API::ApiController
|
|
before_action :authenticate_user!, except: %i[index show]
|
|
before_action :set_component, only: %i[show update destroy]
|
|
|
|
def index
|
|
@components = Component.all
|
|
end
|
|
|
|
def show; end
|
|
|
|
def create
|
|
authorize Component
|
|
@component = Component.new(component_params)
|
|
if @component.save
|
|
render :show, status: :created, location: @component
|
|
else
|
|
render json: @component.errors, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update
|
|
authorize Component
|
|
if @component.update(component_params)
|
|
render :show, status: :ok, location: @component
|
|
else
|
|
render json: @component.errors, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
authorize Component
|
|
@component.destroy
|
|
head :no_content
|
|
end
|
|
|
|
private
|
|
|
|
def set_component
|
|
@component = Component.find(params[:id])
|
|
end
|
|
|
|
def component_params
|
|
params.require(:component).permit(:name)
|
|
end
|
|
end
|