1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-30 11:24:21 +01:00
fab-manager/app/controllers/api/plan_categories_controller.rb

51 lines
1.1 KiB
Ruby
Raw Normal View History

2021-06-08 16:32:19 +02:00
# frozen_string_literal: true
# API Controller for resources of type PlanCategory
# PlanCategory are used to sort plans
class API::PlanCategoriesController < API::ApiController
before_action :authenticate_user!, except: :index
2021-06-08 16:32:19 +02:00
before_action :set_category, only: %i[show update destroy]
def index
2021-06-08 17:00:52 +02:00
@categories = PlanCategory.order(weight: :desc)
2021-06-08 16:32:19 +02:00
end
def show; end
def create
authorize PlanCategory
@category = PlanCategory.new(plan_category_params)
if @category.save
render :show, status: :created, location: @category
else
render json: @category.errors, status: :unprocessable_entity
end
end
def update
authorize @category
if @category.update(plan_category_params)
render :show, status: :ok
else
render json: @category.errors, status: :unprocessable_entity
end
end
def destroy
authorize @category
@category.destroy
head :no_content
end
private
def set_category
@category = PlanCategory.find(params[:id])
end
def plan_category_params
2022-02-03 15:32:02 +01:00
params.require(:plan_category).permit(:name, :weight, :description)
2021-06-08 16:32:19 +02:00
end
end