wedding-planner/app/controllers/guests_controller.rb
Manuel Bustillo 35bf272ac8
Some checks failed
Build Nginx-based docker image / build-static-assets (pull_request) Waiting to run
Add copyright notice / copyright_notice (pull_request) Successful in 4m39s
Run unit tests / unit_tests (pull_request) Failing after 22m29s
Restart simulations whenever a guest changes their invitation status
2024-11-03 09:26:25 +01:00

33 lines
807 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
require 'csv'
class GuestsController < ApplicationController
def index
@guests = Guest.all.includes(:group)
.joins(:group)
.order('groups.name' => :asc, first_name: :asc, last_name: :asc)
render jsonapi: @guests
end
def import
csv = CSV.parse(params[:file].read, headers: true)
ActiveRecord::Base.transaction do
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
def bulk_update
Guests::UpdateUseCase.new(guest_ids: params[:guest_ids], params: params.require(:properties).permit(:status)).call
render json: {}, status: :ok
end
end