1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/controllers/api/slots_controller.rb
Sylvain 0cd841da33 rubocop api controllers
TODO:
 - events controller
 - availabilies controller
 - members controller
 - plans controller
2019-01-16 16:28:25 +01:00

35 lines
903 B
Ruby

# frozen_string_literal: true
# API Controller for resources of type Slot
# Slots are used to cut Availabilities into reservable slots of ApplicationHelper::SLOT_DURATION minutes
class API::SlotsController < API::ApiController
before_action :authenticate_user!
before_action :set_slot, only: %i[update cancel]
respond_to :json
def update
authorize @slot
if @slot.update(slot_params)
SubscriptionExtensionAfterReservation.new(@slot.reservation).extend_subscription_if_eligible
render :show, status: :created, location: @slot
else
render json: @slot.errors, status: :unprocessable_entity
end
end
def cancel
authorize @slot
@slot.update_attributes(canceled_at: DateTime.now)
end
private
def set_slot
@slot = Slot.find(params[:id])
end
def slot_params
params.require(:slot).permit(:start_at, :end_at, :availability_id)
end
end