2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Slot
|
2020-04-15 18:08:02 +02:00
|
|
|
# Slots are used to cut Availabilities into reservable slots. The duration of these slots is configured per
|
2020-05-20 17:36:57 +02:00
|
|
|
# availability by Availability.slot_duration, or otherwise globally by Setting.get('slot_duration')
|
2016-03-23 18:39:41 +01:00
|
|
|
class API::SlotsController < API::ApiController
|
|
|
|
before_action :authenticate_user!
|
2019-01-16 16:28:25 +01:00
|
|
|
before_action :set_slot, only: %i[update cancel]
|
2016-03-23 18:39:41 +01:00
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize @slot
|
|
|
|
if @slot.update(slot_params)
|
2016-04-07 17:57:48 +02:00
|
|
|
SubscriptionExtensionAfterReservation.new(@slot.reservation).extend_subscription_if_eligible
|
2016-03-23 18:39:41 +01:00
|
|
|
render :show, status: :created, location: @slot
|
|
|
|
else
|
|
|
|
render json: @slot.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
authorize @slot
|
2019-06-13 16:29:12 +02:00
|
|
|
SlotService.new.cancel(@slot)
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2019-01-16 16:28:25 +01:00
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
def set_slot
|
|
|
|
@slot = Slot.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def slot_params
|
|
|
|
params.require(:slot).permit(:start_at, :end_at, :availability_id)
|
|
|
|
end
|
|
|
|
end
|