2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type PriceCategory
|
|
|
|
# PriceCategories are used in Events
|
2016-08-24 16:21:43 +02:00
|
|
|
class API::PriceCategoriesController < API::ApiController
|
2019-01-16 16:28:25 +01:00
|
|
|
before_action :authenticate_user!, only: %i[update show create destroy]
|
|
|
|
before_action :set_price_category, only: %i[show update destroy]
|
2016-08-24 12:30:48 +02:00
|
|
|
|
|
|
|
def index
|
|
|
|
@price_categories = PriceCategory.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize PriceCategory
|
|
|
|
if @price_category.update(price_category_params)
|
|
|
|
render :show, status: :ok, location: @price_category
|
|
|
|
else
|
|
|
|
render json: @price_category.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-16 16:28:25 +01:00
|
|
|
def show; end
|
2016-08-24 12:30:48 +02:00
|
|
|
|
|
|
|
def create
|
|
|
|
authorize PriceCategory
|
|
|
|
@price_category = PriceCategory.new(price_category_params)
|
|
|
|
if @price_category.save
|
|
|
|
render :show, status: :created, location: @price_category
|
|
|
|
else
|
|
|
|
render json: @price_category.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize PriceCategory
|
|
|
|
if @price_category.safe_destroy
|
|
|
|
head :no_content
|
|
|
|
else
|
|
|
|
render json: @price_category.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2019-01-16 16:28:25 +01:00
|
|
|
|
2016-08-24 12:30:48 +02:00
|
|
|
def set_price_category
|
|
|
|
@price_category = PriceCategory.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def price_category_params
|
2016-08-24 16:21:43 +02:00
|
|
|
params.require(:price_category).permit(:name, :conditions)
|
2016-08-24 12:30:48 +02:00
|
|
|
end
|
2019-01-16 16:28:25 +01:00
|
|
|
end
|