2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-08-01 18:27:41 +00:00
|
|
|
class TablesArrangementsController < ApplicationController
|
|
|
|
def index
|
2024-11-02 10:40:43 +01:00
|
|
|
render json: TablesArrangement.all.order(discomfort: :asc).limit(10).as_json(only: %i[id discomfort])
|
2024-08-01 18:27:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2024-11-02 10:40:43 +01:00
|
|
|
Seat.joins(:guest).where(tables_arrangement_id: params[:id])
|
2024-11-02 11:23:00 +01:00
|
|
|
.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: } }
|
2024-11-02 10:40:43 +01:00
|
|
|
.then { |result| render json: result }
|
2024-08-01 18:27:41 +00:00
|
|
|
end
|
|
|
|
end
|