33 lines
781 B
Ruby
33 lines
781 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
|
|
Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status))
|
|
render json: {}, status: :ok
|
|
end
|
|
end
|