diff --git a/app/controllers/tables_arrangements_controller.rb b/app/controllers/tables_arrangements_controller.rb index 8523f5a..c741f97 100644 --- a/app/controllers/tables_arrangements_controller.rb +++ b/app/controllers/tables_arrangements_controller.rb @@ -3,12 +3,34 @@ class TablesArrangementsController < ApplicationController def index @tables_arrangements = TablesArrangement.all.order(discomfort: :asc).limit(10) + + respond_to do |format| + format.html + format.json { render json: @tables_arrangements } + end end def show @tables_arrangement = TablesArrangement.find(params[:id]) - @seats = @tables_arrangement.seats - .includes(guest: %i[affinity_groups unbreakable_bonds]) - .group_by(&:table_number) + @seats = @tables_arrangement.seats.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