2022-07-12 17:46:01 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Slot
|
|
|
|
# Slots are used to cut Availabilities into reservable slots. The duration of these slots is configured per
|
|
|
|
# availability by Availability.slot_duration, or otherwise globally by Setting.get('slot_duration')
|
2023-02-24 17:26:55 +01:00
|
|
|
class API::SlotsReservationsController < API::APIController
|
2022-07-12 17:46:01 +02:00
|
|
|
before_action :authenticate_user!
|
2023-07-11 10:36:44 +02:00
|
|
|
before_action :set_slots_reservation, only: %i[update cancel validate invalidate]
|
2022-07-12 17:46:01 +02:00
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize @slot_reservation
|
|
|
|
if @slot_reservation.update(slot_params)
|
2023-02-17 15:35:06 +01:00
|
|
|
Subscriptions::ExtensionAfterReservation.new(@slot_reservation.reservation).extend_subscription_if_eligible
|
2023-01-19 14:28:43 +01:00
|
|
|
render :show, status: :ok, location: @slot_reservation
|
2022-07-12 17:46:01 +02:00
|
|
|
else
|
|
|
|
render json: @slot_reservation.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
authorize @slot_reservation
|
|
|
|
SlotsReservationsService.cancel(@slot_reservation)
|
|
|
|
end
|
|
|
|
|
2023-06-26 16:02:54 +02:00
|
|
|
def validate
|
|
|
|
authorize @slot_reservation
|
|
|
|
SlotsReservationsService.validate(@slot_reservation)
|
|
|
|
end
|
|
|
|
|
2023-07-11 10:36:44 +02:00
|
|
|
def invalidate
|
|
|
|
authorize @slot_reservation
|
|
|
|
SlotsReservationsService.invalidate(@slot_reservation)
|
|
|
|
end
|
|
|
|
|
2022-07-12 17:46:01 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_slots_reservation
|
|
|
|
@slot_reservation = SlotsReservation.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def slot_params
|
|
|
|
params.require(:slots_reservation).permit(:slot_id)
|
|
|
|
end
|
|
|
|
end
|