2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-07-25 10:47:49 +02:00
|
|
|
require 'csv'
|
|
|
|
|
2024-07-11 20:08:26 +02:00
|
|
|
class GuestsController < ApplicationController
|
|
|
|
def index
|
2024-11-01 19:07:12 +01:00
|
|
|
@guests = Guest.all.includes(:group)
|
2024-08-11 18:25:12 +02:00
|
|
|
.joins(:group)
|
2024-10-27 19:13:32 +01:00
|
|
|
.order('groups.name' => :asc, first_name: :asc, last_name: :asc)
|
2024-08-11 18:25:12 +02:00
|
|
|
|
2024-11-01 19:07:12 +01:00
|
|
|
render jsonapi: @guests
|
2024-07-11 20:08:26 +02:00
|
|
|
end
|
|
|
|
|
2024-07-25 10:47:49 +02:00
|
|
|
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
|
|
|
|
|
2024-10-27 14:03:13 +01:00
|
|
|
def bulk_update
|
2024-10-27 19:01:12 +01:00
|
|
|
Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status))
|
2024-10-27 14:03:13 +01:00
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
2024-07-11 20:08:26 +02:00
|
|
|
end
|