Compare commits
	
		
			3 Commits
		
	
	
		
			9b82720b7f
			...
			bd5c4f5482
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| bd5c4f5482 | |||
| d2974edcc1 | |||
| 810d0740f3 | 
| @ -4,4 +4,8 @@ class ExpensesController < ApplicationController | |||||||
|   def summary |   def summary | ||||||
|     render json: Expenses::TotalQuery.new.call |     render json: Expenses::TotalQuery.new.call | ||||||
|   end |   end | ||||||
|  | 
 | ||||||
|  |   def index | ||||||
|  |     render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type]) | ||||||
|  |   end | ||||||
| end | end | ||||||
|  | |||||||
| @ -6,23 +6,14 @@ class GuestsController < ApplicationController | |||||||
|   def index |   def index | ||||||
|     @guests = Guest.all.includes(:group) |     @guests = Guest.all.includes(:group) | ||||||
|                    .joins(:group) |                    .joins(:group) | ||||||
|                    .order('groups.name' => :asc, first_name: :asc, last_name: :asc) |                    .order('groups.name' => :asc, name: :asc) | ||||||
| 
 | 
 | ||||||
|     render jsonapi: @guests |     render jsonapi: @guests | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def import |   def update | ||||||
|     csv = CSV.parse(params[:file].read, headers: true) |     Guests::UpdateUseCase.new(guest_ids: [params[:id]], params: params.require(:guest).permit(:name)).call | ||||||
|     ActiveRecord::Base.transaction do |     render json: {}, status: :ok | ||||||
|       csv.each do |row| |  | ||||||
|         guest = Guest.create!(first_name: row['name']) |  | ||||||
| 
 |  | ||||||
|         guest.affinity_group_list.add(row['affinity_group']) |  | ||||||
|         guest.save! |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     redirect_to guests_url |  | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def bulk_update |   def bulk_update | ||||||
|  | |||||||
| @ -11,7 +11,8 @@ class TablesArrangementsController < ApplicationController | |||||||
|         .order('guests.group_id') |         .order('guests.group_id') | ||||||
|         .pluck( |         .pluck( | ||||||
|           :table_number, |           :table_number, | ||||||
|           Arel.sql("guests.first_name || ' ' || guests.last_name "), 'guests.id', |           'guests.name', | ||||||
|  |           'guests.id', | ||||||
|           'groups.color' |           'groups.color' | ||||||
|         ) |         ) | ||||||
|         .group_by(&:first) |         .group_by(&:first) | ||||||
|  | |||||||
| @ -12,8 +12,4 @@ class Guest < ApplicationRecord | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   scope :potential, -> { where.not(status: %i[declined considered]) } |   scope :potential, -> { where.not(status: %i[declined considered]) } | ||||||
| 
 |  | ||||||
|   def full_name |  | ||||||
|     "#{first_name} #{last_name}" |  | ||||||
|   end |  | ||||||
| end | end | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ class SerializableGuest < JSONAPI::Serializable::Resource | |||||||
|   attributes :id, :group_id, :status |   attributes :id, :group_id, :status | ||||||
| 
 | 
 | ||||||
|   attribute :name do |   attribute :name do | ||||||
|     "#{@object.first_name} #{@object.last_name}" |     @object.name | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   attribute :group_name do |   attribute :group_name do | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ module Tables | |||||||
| 
 | 
 | ||||||
|     def pretty_print |     def pretty_print | ||||||
|       @tables.map.with_index do |table, i| |       @tables.map.with_index do |table, i| | ||||||
|         "Table #{i + 1} (#{table.count} ppl): (#{local_discomfort(table)}) #{table.map(&:full_name).join(', ')}" |         "Table #{i + 1} (#{table.count} ppl): (#{local_discomfort(table)}) #{table.map(&:name).join(', ')}" | ||||||
|       end.join("\n") |       end.join("\n") | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -12,6 +12,8 @@ module Guests | |||||||
|       Guest.where(id: guest_ids).update!(params) |       Guest.where(id: guest_ids).update!(params) | ||||||
| 
 | 
 | ||||||
|       # TODO: Not all status transitions may require a table re-arrangement |       # TODO: Not all status transitions may require a table re-arrangement | ||||||
|  |       return unless params.key?(:status) | ||||||
|  | 
 | ||||||
|       TablesArrangement.delete_all |       TablesArrangement.delete_all | ||||||
| 
 | 
 | ||||||
|       ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new }) |       ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new }) | ||||||
|  | |||||||
| @ -3,13 +3,12 @@ | |||||||
| Rails.application.routes.draw do | Rails.application.routes.draw do | ||||||
|   resources :groups, only: :index |   resources :groups, only: :index | ||||||
|   resources :guests do |   resources :guests do | ||||||
|     post :import, on: :collection |  | ||||||
|     post :bulk_update, on: :collection |     post :bulk_update, on: :collection | ||||||
|   end |   end | ||||||
|   resources :expenses do |   resources :expenses, only: %i[index update] do | ||||||
|     get :summary, on: :collection |     get :summary, on: :collection | ||||||
|   end |   end | ||||||
|   resources :tables_arrangements, only: [:index, :show] |   resources :tables_arrangements, only: %i[index show] | ||||||
| 
 | 
 | ||||||
|   get 'up' => 'rails/health#show', as: :rails_health_check |   get 'up' => 'rails/health#show', as: :rails_health_check | ||||||
| end | end | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								db/migrate/20241111063741_merge_guest_names.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								db/migrate/20241111063741_merge_guest_names.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | class MergeGuestNames < ActiveRecord::Migration[8.0] | ||||||
|  |   def change | ||||||
|  |     add_column :guests, :name, :string | ||||||
|  | 
 | ||||||
|  |     reversible do |dir| | ||||||
|  |       dir.up do | ||||||
|  |         execute <<~SQL | ||||||
|  |           UPDATE guests | ||||||
|  |           SET name = CONCAT(first_name, ' ', last_name) | ||||||
|  |         SQL | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     remove_column :guests, :first_name, :string | ||||||
|  |     remove_column :guests, :last_name, :string | ||||||
|  |   end | ||||||
|  | end | ||||||
							
								
								
									
										9
									
								
								db/schema.rb
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9
									
								
								db/schema.rb
									
									
									
										generated
									
									
									
								
							| @ -1,5 +1,3 @@ | |||||||
| # Copyright (C) 2024 Manuel Bustillo |  | ||||||
| 
 |  | ||||||
| # This file is auto-generated from the current state of the database. Instead | # This file is auto-generated from the current state of the database. Instead | ||||||
| # of editing this file, please use the migrations feature of Active Record to | # of editing this file, please use the migrations feature of Active Record to | ||||||
| # incrementally modify your database, and then regenerate this schema definition. | # incrementally modify your database, and then regenerate this schema definition. | ||||||
| @ -12,9 +10,9 @@ | |||||||
| # | # | ||||||
| # It's strongly recommended that you check this file into your version control system. | # It's strongly recommended that you check this file into your version control system. | ||||||
| 
 | 
 | ||||||
| ActiveRecord::Schema[7.2].define(version: 2024_11_03_133122) do | ActiveRecord::Schema[8.0].define(version: 2024_11_11_063741) do | ||||||
|   # These are extensions that must be enabled in order to support this database |   # These are extensions that must be enabled in order to support this database | ||||||
|   enable_extension "plpgsql" |   enable_extension "pg_catalog.plpgsql" | ||||||
| 
 | 
 | ||||||
|   # Custom types defined in this database. |   # Custom types defined in this database. | ||||||
|   # Note that some types may not work with other database engines. Be careful if changing database. |   # Note that some types may not work with other database engines. Be careful if changing database. | ||||||
| @ -41,13 +39,12 @@ ActiveRecord::Schema[7.2].define(version: 2024_11_03_133122) do | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   create_table "guests", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| |   create_table "guests", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| | ||||||
|     t.string "first_name" |  | ||||||
|     t.string "last_name" |  | ||||||
|     t.string "phone" |     t.string "phone" | ||||||
|     t.datetime "created_at", null: false |     t.datetime "created_at", null: false | ||||||
|     t.datetime "updated_at", null: false |     t.datetime "updated_at", null: false | ||||||
|     t.uuid "group_id", null: false |     t.uuid "group_id", null: false | ||||||
|     t.integer "status", default: 0 |     t.integer "status", default: 0 | ||||||
|  |     t.string "name" | ||||||
|     t.index ["group_id"], name: "index_guests_on_group_id" |     t.index ["group_id"], name: "index_guests_on_group_id" | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -56,8 +56,7 @@ groups = Group.all | |||||||
| 
 | 
 | ||||||
| NUMBER_OF_GUESTS.times do | NUMBER_OF_GUESTS.times do | ||||||
|   Guest.create!( |   Guest.create!( | ||||||
|     first_name: Faker::Name.first_name, |     name: Faker::Name.name, | ||||||
|     last_name: Faker::Name.last_name, |  | ||||||
|     phone: Faker::PhoneNumber.cell_phone, |     phone: Faker::PhoneNumber.cell_phone, | ||||||
|     group: groups.sample, |     group: groups.sample, | ||||||
|     status: Guest.statuses.keys.sample |     status: Guest.statuses.keys.sample | ||||||
|  | |||||||
| @ -4,8 +4,7 @@ FactoryBot.define do | |||||||
|   factory :guest do |   factory :guest do | ||||||
|     association :group |     association :group | ||||||
| 
 | 
 | ||||||
|     first_name { Faker::Name.first_name } |     name { Faker::Name.name } | ||||||
|     last_name { Faker::Name.last_name } |  | ||||||
|     phone { Faker::PhoneNumber.cell_phone } |     phone { Faker::PhoneNumber.cell_phone } | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  | |||||||
| @ -28,12 +28,4 @@ RSpec.describe Guest, type: :model do | |||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 |  | ||||||
|   describe '#full_name' do |  | ||||||
|     it 'returns the full name of the guest' do |  | ||||||
|       guest = create(:guest, first_name: 'John', last_name: 'Doe') |  | ||||||
| 
 |  | ||||||
|       expect(guest.full_name).to eq('John Doe') |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
| end | end | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user