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

58 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for resources of type Space
2017-02-13 16:10:12 +01:00
class API::SpacesController < API::ApiController
before_action :authenticate_user!, except: %i[index show]
before_action :set_space, only: %i[update destroy]
2017-02-13 16:10:12 +01:00
respond_to :json
def index
2022-11-22 14:17:25 +01:00
@spaces = Space.includes(:space_image).where(deleted_at: nil)
2017-02-13 16:10:12 +01:00
end
def show
@space = Space.includes(:space_files, :projects).friendly.find(params[:id])
2022-11-22 14:17:25 +01:00
head :not_found if @space.deleted_at
2017-02-13 16:10:12 +01:00
end
def create
authorize Space
@space = Space.new(space_params)
if @space.save
render :show, status: :created, location: @space
else
render json: @space.errors, status: :unprocessable_entity
end
end
def update
authorize @space
2017-02-13 16:10:12 +01:00
if @space.update(space_params)
render :show, status: :ok, location: @space
else
render json: @space.errors, status: :unprocessable_entity
end
end
def destroy
authorize @space
method = @space.destroyable? ? :destroy : :soft_destroy!
@space.send(method)
2017-02-13 16:10:12 +01:00
head :no_content
end
private
def set_space
@space = Space.friendly.find(params[:id])
end
def space_params
params.require(:space).permit(:name, :description, :characteristics, :default_places, :disabled,
space_image_attributes: [:attachment],
space_files_attributes: %i[id attachment _destroy],
advanced_accounting_attributes: %i[code analytical_section])
end
2017-02-13 16:10:12 +01:00
end