All checks were successful
		
		
	
	Run unit tests / copyright_notice (pull_request) Successful in 29s
				
			Run unit tests / rubocop (pull_request) Successful in 2m13s
				
			Run unit tests / check-licenses (pull_request) Successful in 2m35s
				
			Run unit tests / unit_tests (pull_request) Successful in 3m23s
				
			Run unit tests / build-static-assets (pull_request) Successful in 18m43s
				
			
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | 
						|
 | 
						|
# frozen_string_literal: true
 | 
						|
 | 
						|
require 'csv'
 | 
						|
 | 
						|
class GuestsController < ApplicationController
 | 
						|
  GUEST_PARAMS = { only: %i[id name status], include: { group: { only: %i[id name] } } }.freeze
 | 
						|
 | 
						|
  skip_before_action :authenticate_user!, only: :update
 | 
						|
 | 
						|
  def index
 | 
						|
    render json: Guest.includes(:group)
 | 
						|
                      .left_joins(:group)
 | 
						|
                      .order('groups.name' => :asc, invitation_id: :asc, name: :asc)
 | 
						|
                      .as_json(GUEST_PARAMS)
 | 
						|
  end
 | 
						|
 | 
						|
  def create
 | 
						|
    guest = Guest.create!(guest_params)
 | 
						|
    render json: guest.as_json(GUEST_PARAMS), status: :created
 | 
						|
  end
 | 
						|
 | 
						|
  def update
 | 
						|
    guest = Guest.find(params[:id])
 | 
						|
    guest.update!(guest_params)
 | 
						|
 | 
						|
    if !user_signed_in? && guest.saved_change_to_status?
 | 
						|
      AdminMailer.with(guest_id: guest.id).attendance_change_email.deliver_later
 | 
						|
    end
 | 
						|
 | 
						|
    render json: guest.as_json(GUEST_PARAMS), status: :ok
 | 
						|
  end
 | 
						|
 | 
						|
  def destroy
 | 
						|
    Guest.find(params[:id]).destroy!
 | 
						|
    render json: {}, status: :ok
 | 
						|
  end
 | 
						|
 | 
						|
  private
 | 
						|
 | 
						|
  def guest_params
 | 
						|
    user_signed_in? ? params.expect(guest: %i[name group_id status]) : params.expect(guest: %i[status])
 | 
						|
  end
 | 
						|
end
 |