All checks were successful
		
		
	
	Run unit tests / copyright_notice (pull_request) Successful in 56s
				
			Run unit tests / rubocop (pull_request) Successful in 1m10s
				
			Run unit tests / check-licenses (pull_request) Successful in 1m20s
				
			Run unit tests / unit_tests (pull_request) Successful in 2m3s
				
			Run unit tests / build-static-assets (pull_request) Successful in 9m10s
				
			
		
			
				
	
	
		
			77 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | 
						|
 | 
						|
# frozen_string_literal: true
 | 
						|
 | 
						|
class InvitationsController < ApplicationController
 | 
						|
  skip_before_action :authenticate_user!, only: :show
 | 
						|
 | 
						|
  def index
 | 
						|
    @invitations = Invitation.includes(:guests).all
 | 
						|
    respond_to do |format|
 | 
						|
      format.json do
 | 
						|
        render json: @invitations.as_json(
 | 
						|
          only: :id,
 | 
						|
          include: { guests: { only: %i[id name] } }
 | 
						|
        )
 | 
						|
      end
 | 
						|
      format.pdf do
 | 
						|
        pdf_html = ActionController::Base.new.render_to_string(
 | 
						|
          template: 'invitations/sheet',
 | 
						|
          layout: 'pdf',
 | 
						|
          locals: { invitations: @invitations }
 | 
						|
        )
 | 
						|
        pdf = WickedPdf.new.pdf_from_string(pdf_html)
 | 
						|
        send_data pdf, filename: "invitations_#{Time.current.strftime('%Y%m%d_%H%M%S')}.pdf"
 | 
						|
      end
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def email
 | 
						|
    AdminMailer.with(wedding_id: ActsAsTenant.current_tenant.id).invitations_pdf_email.deliver_later
 | 
						|
 | 
						|
    head :ok
 | 
						|
  end
 | 
						|
 | 
						|
  def sheet; end
 | 
						|
 | 
						|
  def show
 | 
						|
    invitation = Invitation.includes(:guests).find(params[:id])
 | 
						|
 | 
						|
    if invitation
 | 
						|
      render json: invitation, only: :id, include: { guests: { only: %i[id name status] } }, status: :ok
 | 
						|
    else
 | 
						|
      render json: { error: 'Invitation not found' }, status: :not_found
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def create
 | 
						|
    invitation = Invitation.create
 | 
						|
 | 
						|
    if invitation.persisted?
 | 
						|
      render json: invitation, only: :id, status: :created
 | 
						|
    else
 | 
						|
      render json: { errors: invitation.errors.full_messages }, status: :unprocessable_entity
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def update
 | 
						|
    invitation = Invitation.find(params[:id])
 | 
						|
 | 
						|
    if invitation.update(guest_ids: params[:invitation][:guest_ids])
 | 
						|
      render json: invitation, only: :id, include: { guests: { only: %i[id name] } }, status: :ok
 | 
						|
    else
 | 
						|
      render json: { errors: invitation.errors.full_messages }, status: :unprocessable_entity
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def destroy
 | 
						|
    invitation = Invitation.find(params[:id])
 | 
						|
 | 
						|
    if invitation.destroy
 | 
						|
      head :no_content
 | 
						|
    else
 | 
						|
      render json: { errors: invitation.errors.full_messages }, status: :unprocessable_entity
 | 
						|
    end
 | 
						|
  end
 | 
						|
end
 |