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