# Copyright (C) 2024-2025 LibreWeddingPlanner contributors class InvitationsController < ApplicationController def index render json: Invitation.includes(:guests).as_json( only: :id, include: { guests: { only: %i[id name] } } ) 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