# 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