From 1e1b3f19fc7ff6011095c7019ee55b50dcdd3aae Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 21 Sep 2025 21:08:01 +0200 Subject: [PATCH 1/4] Define an endpoint with table simulation stats --- .../tables_arrangements_controller.rb | 29 ++++++++++++++----- config/routes.rb | 4 ++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/controllers/tables_arrangements_controller.rb b/app/controllers/tables_arrangements_controller.rb index 184b577..7340f9f 100644 --- a/app/controllers/tables_arrangements_controller.rb +++ b/app/controllers/tables_arrangements_controller.rb @@ -4,17 +4,28 @@ class TablesArrangementsController < ApplicationController def index - current_digest = Tables::Distribution.digest(current_tenant) + query = TablesArrangement + .order(valid: :desc) + .order(discomfort: :asc) + .select(:id, :name, :discomfort, :status, :progress) + .select("digest = '#{current_digest}'::uuid OR discomfort IS NULL as valid") + .limit((params[:limit].presence&.to_i || 20).clamp(1..20)) - render json: TablesArrangement - .order(valid: :desc) - .order(discomfort: :asc) - .select(:id, :name, :discomfort, :status, :progress) - .select("digest = '#{current_digest}'::uuid OR discomfort IS NULL as valid") - .limit(20) + query = query.where(status: params[:status]) if params[:status].present? + + render json: query .as_json(only: %i[id name discomfort valid status progress]) end + def stats + scope = TablesArrangement.where('digest = ?::uuid OR discomfort IS NULL', current_digest) + + render json: { + count: scope.group(:status).count, + in_progress: scope.where(status: :in_progress).limit(10).order(progress: :desc).pluck(:progress) + } + end + def show Guest.joins(:seats, :group) .where(seats: { tables_arrangement_id: params[:id] }) @@ -35,6 +46,10 @@ class TablesArrangementsController < ApplicationController private + def current_digest + @current_digest ||= Tables::Distribution.digest(current_tenant) + end + def format(number:, guests:) { number: number, diff --git a/config/routes.rb b/config/routes.rb index d9d4bf0..4490024 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,7 +40,9 @@ Rails.application.routes.draw do resource :website, only: [:show, :update] - resources :tables_arrangements, only: %i[index show create] + resources :tables_arrangements, only: %i[index show create] do + get :stats, on: :collection + end resources :summary, only: :index resources :invitations, only: %i[show index create update destroy] do post :email, on: :collection -- 2.47.1 From 725b9287da4590b16e10416b3c839af9255b084f Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 21 Sep 2025 23:47:23 +0200 Subject: [PATCH 2/4] Pin the version of the setup-ruby Github action --- .gitea/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index 0fba0ab..b6359e8 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} ref: ${{ github.head_ref }} # Checkout the actual branch, not the result if merged into the base - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@v1.262.0 - run: bundle install - &postgres_wait name: Wait until Postgres is ready to accept connections @@ -71,7 +71,7 @@ jobs: - uses: actions/checkout@v5 with: token: ${{ secrets.GITHUB_TOKEN }} - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@v1.262.0 - run: bundle install - run: bundle exec rubocop --force-exclusion --parallel check-licenses: @@ -81,7 +81,7 @@ jobs: - uses: actions/checkout@v5 with: token: ${{ secrets.GITHUB_TOKEN }} - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@v1.262.0 - name: Install project dependencies run: bundle install --jobs `getconf _NPROCESSORS_ONLN` - name: Run license finder -- 2.47.1 From 01a5feed09be583cebf0c20de0d29393b16ac588 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 21 Sep 2025 23:53:35 +0200 Subject: [PATCH 3/4] Revert "Pin the version of the setup-ruby Github action" This reverts commit 725b9287da4590b16e10416b3c839af9255b084f. --- .gitea/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index b6359e8..0fba0ab 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} ref: ${{ github.head_ref }} # Checkout the actual branch, not the result if merged into the base - - uses: ruby/setup-ruby@v1.262.0 + - uses: ruby/setup-ruby@v1 - run: bundle install - &postgres_wait name: Wait until Postgres is ready to accept connections @@ -71,7 +71,7 @@ jobs: - uses: actions/checkout@v5 with: token: ${{ secrets.GITHUB_TOKEN }} - - uses: ruby/setup-ruby@v1.262.0 + - uses: ruby/setup-ruby@v1 - run: bundle install - run: bundle exec rubocop --force-exclusion --parallel check-licenses: @@ -81,7 +81,7 @@ jobs: - uses: actions/checkout@v5 with: token: ${{ secrets.GITHUB_TOKEN }} - - uses: ruby/setup-ruby@v1.262.0 + - uses: ruby/setup-ruby@v1 - name: Install project dependencies run: bundle install --jobs `getconf _NPROCESSORS_ONLN` - name: Run license finder -- 2.47.1 From 879a6803e7e8d10c6466b6eb33d29bedb92d84d5 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 21 Sep 2025 23:54:13 +0200 Subject: [PATCH 4/4] Upgrade bundler --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d4f50bb..bee2ae4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -663,4 +663,4 @@ RUBY VERSION ruby 3.4.3p32 BUNDLED WITH - 2.6.1 + 2.7.2 -- 2.47.1