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/slots_reservations_controller.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

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')
class API::SlotsReservationsController < API::ApiController
before_action :authenticate_user!
before_action :set_slots_reservation, only: %i[update cancel]
respond_to :json
def update
authorize @slot_reservation
if @slot_reservation.update(slot_params)
SubscriptionExtensionAfterReservation.new(@slot_reservation.reservation).extend_subscription_if_eligible
render :show, status: :created, location: @slot_reservation
else
render json: @slot_reservation.errors, status: :unprocessable_entity
end
end
def cancel
authorize @slot_reservation
SlotsReservationsService.cancel(@slot_reservation)
end
private
def set_slots_reservation
@slot_reservation = SlotsReservation.find(params[:id])
end
def slot_params
params.require(:slots_reservation).permit(:slot_id)
end
end