wedding-planner/app/controllers/tables_arrangements_controller.rb

17 lines
621 B
Ruby
Raw Normal View History

2024-10-27 21:42:45 +00:00
# Copyright (C) 2024 Manuel Bustillo
class TablesArrangementsController < ApplicationController
def index
2024-11-02 12:50:45 +01:00
render json: TablesArrangement.all.order(discomfort: :asc).limit(3).as_json(only: %i[id discomfort])
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 }
end
end