2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Licence
|
|
|
|
# Licenses are used in Projects
|
2015-05-05 03:10:25 +02:00
|
|
|
class API::LicencesController < API::ApiController
|
2019-01-16 16:28:25 +01:00
|
|
|
before_action :authenticate_user!, except: %i[index show]
|
|
|
|
before_action :set_licence, only: %i[show update destroy]
|
2015-05-05 03:10:25 +02:00
|
|
|
|
|
|
|
def index
|
|
|
|
@licences = Licence.all
|
|
|
|
end
|
|
|
|
|
2019-01-16 16:28:25 +01:00
|
|
|
def show; end
|
2015-05-05 03:10:25 +02:00
|
|
|
|
|
|
|
def create
|
|
|
|
authorize Licence
|
|
|
|
@licence = Licence.new(licence_params)
|
|
|
|
if @licence.save
|
|
|
|
render :show, status: :created, location: @licence
|
|
|
|
else
|
|
|
|
render json: @licence.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize Licence
|
|
|
|
if @licence.update(licence_params)
|
|
|
|
render :show, status: :ok, location: @licence
|
|
|
|
else
|
|
|
|
render json: @licence.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize Licence
|
|
|
|
@licence.destroy
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-01-16 16:28:25 +01:00
|
|
|
def set_licence
|
|
|
|
@licence = Licence.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def licence_params
|
|
|
|
params.require(:licence).permit(:name, :description)
|
|
|
|
end
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|