wedding-planner/app/controllers/tables_arrangements_controller.rb
Manuel Bustillo be9f61e03e
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
Expose tables via API
2024-11-01 19:01:48 +01:00

37 lines
888 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
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.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