2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type EventTheme
|
|
|
|
# EventTheme are used to classify Events
|
2016-06-29 10:38:04 +02:00
|
|
|
class API::EventThemesController < API::ApiController
|
2016-06-29 16:09:27 +02:00
|
|
|
before_action :authenticate_user!, except: [:index]
|
2019-01-16 16:28:25 +01:00
|
|
|
before_action :set_event_theme, only: %i[show update destroy]
|
2016-06-29 10:38:04 +02:00
|
|
|
|
|
|
|
def index
|
|
|
|
@event_themes = EventTheme.all
|
|
|
|
end
|
|
|
|
|
2019-01-16 16:28:25 +01:00
|
|
|
def show; end
|
2016-06-29 10:38:04 +02:00
|
|
|
|
|
|
|
def create
|
|
|
|
authorize EventTheme
|
|
|
|
@event_theme = EventTheme.new(event_theme_params)
|
|
|
|
if @event_theme.save
|
|
|
|
render :show, status: :created, location: @event_theme
|
|
|
|
else
|
|
|
|
render json: @event_theme.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize EventTheme
|
|
|
|
if @event_theme.update(event_theme_params)
|
|
|
|
render :show, status: :ok, location: @event_theme
|
|
|
|
else
|
|
|
|
render json: @event_theme.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize EventTheme
|
2016-06-30 11:39:56 +02:00
|
|
|
if @event_theme.safe_destroy
|
|
|
|
head :no_content
|
|
|
|
else
|
|
|
|
render json: @event_theme.errors, status: :unprocessable_entity
|
|
|
|
end
|
2016-06-29 10:38:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2019-01-16 16:28:25 +01:00
|
|
|
|
2016-06-29 10:38:04 +02:00
|
|
|
def set_event_theme
|
|
|
|
@event_theme = EventTheme.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_theme_params
|
|
|
|
params.require(:event_theme).permit(:name)
|
|
|
|
end
|
|
|
|
end
|