Define an endpoint with table simulation stats #324
@ -663,4 +663,4 @@ RUBY VERSION
|
||||
ruby 3.4.3p32
|
||||
|
||||
BUNDLED WITH
|
||||
2.6.1
|
||||
2.7.2
|
||||
|
||||
@ -4,17 +4,28 @@
|
||||
|
||||
class TablesArrangementsController < ApplicationController
|
||||
def index
|
||||
current_digest = Tables::Distribution.digest(current_tenant)
|
||||
|
||||
render json: TablesArrangement
|
||||
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(20)
|
||||
.limit((params[:limit].presence&.to_i || 20).clamp(1..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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user