Expose tables via API #80
@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
class TablesArrangementsController < ApplicationController
|
class TablesArrangementsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
render json: TablesArrangement.all.order(discomfort: :asc).limit(10)
|
render json: TablesArrangement.all.order(discomfort: :asc).limit(3).as_json(only: %i[id discomfort])
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render json: TablesArrangement.find(params[:id])
|
Seat.joins(:guest).where(tables_arrangement_id: params[:id])
|
||||||
|
.pluck(:table_number, Arel.sql("guests.first_name || ' ' || guests.last_name "), 'guests.id')
|
||||||
|
.group_by(&:first)
|
||||||
|
.transform_values { |table| table.map { |(_, name, id)| { id:, name: } } }
|
||||||
|
.map { |number, guests| { number:, guests: } }
|
||||||
|
.then { |result| render json: result }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
class TablesArrangement < ApplicationRecord
|
class TablesArrangement < ApplicationRecord
|
||||||
has_many :seats
|
has_many :seats
|
||||||
|
has_many :guests, through: :seats
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user