Compare commits
No commits in common. "998c0f43f3ef3dcd08eb8b6fdc514506a223daae" and "d1a351ffec951c8fb5d57580944539e99886a070" have entirely different histories.
998c0f43f3
...
d1a351ffec
@ -4,15 +4,7 @@
|
|||||||
|
|
||||||
class TablesArrangementsController < ApplicationController
|
class TablesArrangementsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
current_digest = Tables::Distribution.digest(current_tenant)
|
render json: TablesArrangement.order(discomfort: :asc).limit(3).as_json(only: %i[id name discomfort])
|
||||||
|
|
||||||
render json: TablesArrangement
|
|
||||||
.order(valid: :desc)
|
|
||||||
.order(discomfort: :asc)
|
|
||||||
.select(:id, :name, :discomfort)
|
|
||||||
.select("digest = '#{current_digest}'::uuid as valid")
|
|
||||||
.limit(20)
|
|
||||||
.as_json(only: %i[id name discomfort valid])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ -24,12 +16,6 @@ class TablesArrangementsController < ApplicationController
|
|||||||
.then { |result| render json: { id: params[:id], tables: result } }
|
.then { |result| render json: { id: params[:id], tables: result } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
|
||||||
TableSimulatorJob.perform_later(current_tenant.id)
|
|
||||||
|
|
||||||
render json: {}, status: :created
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def format(number:, guests:)
|
def format(number:, guests:)
|
||||||
|
@ -41,5 +41,16 @@ class Guest < ApplicationRecord
|
|||||||
|
|
||||||
scope :potential, -> { where.not(status: %i[declined considered]) }
|
scope :potential, -> { where.not(status: %i[declined considered]) }
|
||||||
|
|
||||||
|
after_destroy :recalculate_simulations
|
||||||
|
after_save :recalculate_simulations, if: :saved_change_to_status?
|
||||||
|
|
||||||
has_many :seats, dependent: :delete_all
|
has_many :seats, dependent: :delete_all
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def recalculate_simulations
|
||||||
|
TablesArrangement.delete_all
|
||||||
|
|
||||||
|
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new(wedding_id) })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
# Table name: tables_arrangements
|
# Table name: tables_arrangements
|
||||||
#
|
#
|
||||||
# id :uuid not null, primary key
|
# id :uuid not null, primary key
|
||||||
# digest :uuid not null
|
|
||||||
# discomfort :integer
|
# discomfort :integer
|
||||||
|
# guests_digest :uuid not null
|
||||||
# name :string not null
|
# name :string not null
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
@ -19,6 +19,4 @@ class Wedding < ApplicationRecord
|
|||||||
SLUG_REGEX = /[a-z\d-]+/
|
SLUG_REGEX = /[a-z\d-]+/
|
||||||
|
|
||||||
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ }
|
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ }
|
||||||
|
|
||||||
has_many :guests, dependent: :delete_all
|
|
||||||
end
|
end
|
||||||
|
@ -6,13 +6,7 @@ require_relative '../../extensions/tree_node_extension'
|
|||||||
|
|
||||||
module Tables
|
module Tables
|
||||||
class Distribution
|
class Distribution
|
||||||
class << self
|
attr_accessor :tables, :min_per_table, :max_per_table
|
||||||
def digest(wedding)
|
|
||||||
Digest::UUID.uuid_v5(wedding.id, wedding.guests.potential.order(:id).pluck(:id).join)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_accessor :tables, :min_per_table, :max_per_table, :hierarchy
|
|
||||||
|
|
||||||
def initialize(min_per_table:, max_per_table:)
|
def initialize(min_per_table:, max_per_table:)
|
||||||
@min_per_table = min_per_table
|
@min_per_table = min_per_table
|
||||||
@ -60,10 +54,7 @@ module Tables
|
|||||||
|
|
||||||
Seat.insert_all!(records_to_store)
|
Seat.insert_all!(records_to_store)
|
||||||
|
|
||||||
arrangement.update!(
|
arrangement.update!(discomfort:)
|
||||||
discomfort:,
|
|
||||||
digest: self.class.digest(tables.first.first.wedding)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ Rails.application.routes.draw do
|
|||||||
resources :expenses, only: %i[index create update destroy] do
|
resources :expenses, only: %i[index create update destroy] do
|
||||||
get :summary, on: :collection
|
get :summary, on: :collection
|
||||||
end
|
end
|
||||||
resources :tables_arrangements, only: %i[index show create]
|
resources :tables_arrangements, only: %i[index show]
|
||||||
resources :summary, only: :index
|
resources :summary, only: :index
|
||||||
|
|
||||||
root to: redirect("/%{slug}")
|
root to: redirect("/%{slug}")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class AddGuestsDigestColumnToTablesArrangements < ActiveRecord::Migration[8.0]
|
class AddGuestsDigestColumnToTablesArrangements < ActiveRecord::Migration[8.0]
|
||||||
def change
|
def change
|
||||||
add_column :tables_arrangements, :digest, :uuid, null: false, default: 'gen_random_uuid()'
|
add_column :tables_arrangements, :guests_digest, :uuid, null: false, default: 'gen_random_uuid()'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
2
db/schema.rb
generated
2
db/schema.rb
generated
@ -206,7 +206,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_26_091823) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.uuid "wedding_id", null: false
|
t.uuid "wedding_id", null: false
|
||||||
t.uuid "digest", default: -> { "gen_random_uuid()" }, null: false
|
t.uuid "guests_digest", default: -> { "gen_random_uuid()" }, null: false
|
||||||
t.index ["wedding_id"], name: "index_tables_arrangements_on_wedding_id"
|
t.index ["wedding_id"], name: "index_tables_arrangements_on_wedding_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,27 +18,13 @@ RSpec.describe 'tables_arrangements' do
|
|||||||
properties: {
|
properties: {
|
||||||
id: { type: :string, format: :uuid },
|
id: { type: :string, format: :uuid },
|
||||||
name: { type: :string },
|
name: { type: :string },
|
||||||
discomfort: { type: :integer },
|
discomfort: { type: :integer }
|
||||||
valid: { type: :boolean }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
regular_api_responses
|
regular_api_responses
|
||||||
end
|
end
|
||||||
|
|
||||||
post('create tables arrangement') do
|
|
||||||
tags 'Tables Arrangements'
|
|
||||||
produces 'application/json'
|
|
||||||
parameter Swagger::Schema::SLUG
|
|
||||||
response(201, 'successful') do
|
|
||||||
schema type: :object,
|
|
||||||
required: [],
|
|
||||||
properties: {}
|
|
||||||
xit
|
|
||||||
end
|
|
||||||
regular_api_responses
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
path '/{slug}/tables_arrangements/{id}' do
|
path '/{slug}/tables_arrangements/{id}' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user