Merge pull request 'Recreate simulations whenever a guest changes their attendance' (#85) from simulations-lifecycle into main
Some checks failed
Check usage of free licenses / build-static-assets (push) Successful in 43s
Run unit tests / unit_tests (push) Successful in 1m46s
Build Nginx-based docker image / build-static-assets (push) Failing after 2m54s

Reviewed-on: #85
This commit is contained in:
bustikiller 2024-11-03 12:51:13 +00:00
commit c2989b216f
4 changed files with 19 additions and 3 deletions

View File

@ -26,7 +26,7 @@ class GuestsController < ApplicationController
end end
def bulk_update 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 render json: {}, status: :ok
end end
end end

View File

@ -9,7 +9,7 @@ class TableSimulatorJob < ApplicationJob
engine.add_perturbation(Tables::Swap) engine.add_perturbation(Tables::Swap)
initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10) initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10)
initial_solution.random_distribution(Guest.all.shuffle) initial_solution.random_distribution(Guest.potential.shuffle)
engine.initial_solution = initial_solution engine.initial_solution = initial_solution

View File

@ -8,9 +8,11 @@ class Guest < ApplicationRecord
invited: 10, invited: 10,
confirmed: 20, confirmed: 20,
declined: 30, declined: 30,
tentative: 40, tentative: 40
} }
scope :potential, -> { where.not(status: %i[declined considered]) }
def full_name def full_name
"#{first_name} #{last_name}" "#{first_name} #{last_name}"
end end

View File

@ -0,0 +1,14 @@
# Copyright (C) 2024 Manuel Bustillo
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