1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-15 00:24:09 +01:00
fab-manager/app/controllers/api/licences_controller.rb

50 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for resources of type Licence
# Licenses are used in Projects
2023-02-24 17:26:55 +01:00
class API::LicencesController < API::APIController
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
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
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