Expose tables via API
All checks were successful
Add copyright notice / copyright_notice (pull_request) Successful in 56s
Run unit tests / unit_tests (pull_request) Successful in 1m27s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 48m2s

This commit is contained in:
Manuel Bustillo 2024-11-01 19:01:48 +01:00
parent 62a7af6db3
commit be9f61e03e

View File

@ -3,12 +3,34 @@
class TablesArrangementsController < ApplicationController class TablesArrangementsController < ApplicationController
def index def index
@tables_arrangements = TablesArrangement.all.order(discomfort: :asc).limit(10) @tables_arrangements = TablesArrangement.all.order(discomfort: :asc).limit(10)
respond_to do |format|
format.html
format.json { render json: @tables_arrangements }
end
end end
def show def show
@tables_arrangement = TablesArrangement.find(params[:id]) @tables_arrangement = TablesArrangement.find(params[:id])
@seats = @tables_arrangement.seats @seats = @tables_arrangement.seats.group_by(&:table_number)
.includes(guest: %i[affinity_groups unbreakable_bonds])
.group_by(&:table_number) respond_to do |format|
format.html
format.json do
render json: {
tables: @seats.map do |table_number, seats|
{
table_number: table_number,
guests: seats.map do |seat|
{
guest: seat.guest,
group: seat.guest.group,
}
end
}
end
}
end
end
end end
end end