Expose tables via API
This commit is contained in:
parent
62a7af6db3
commit
be9f61e03e
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user