wedding-planner/app/controllers/guests_controller.rb

33 lines
807 B
Ruby
Raw Normal View History

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
@guests = Guest.all.includes(:group)
.joins(:group)
.order('groups.name' => :asc, first_name: :asc, last_name: :asc)
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
def bulk_update
Guests::UpdateUseCase.new(guest_ids: params[:guest_ids], params: params.require(:properties).permit(:status)).call
render json: {}, status: :ok
end
2024-07-11 20:08:26 +02:00
end