diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index ecf5d34..de6127d 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -26,7 +26,7 @@ class GuestsController < ApplicationController end def bulk_update - Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status)) + Guests::UpdateUseCase.new(guest_ids: params[:guest_ids], params: params.require(:properties).permit(:status)).call render json: {}, status: :ok end end diff --git a/app/use_cases/guests/update_use_case.rb b/app/use_cases/guests/update_use_case.rb new file mode 100644 index 0000000..bcd4f3e --- /dev/null +++ b/app/use_cases/guests/update_use_case.rb @@ -0,0 +1,12 @@ +module Guests + class UpdateUseCase + def initialize(guest_ids:, params:) + Guest.where(id: guest_ids).update!(params) + + # TODO: Not all status transitions may require a table re-arrangement + TablesArrangement.delete_all + + ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new }) + end + end +end