wedding-planner/app/controllers/invitations_controller.rb
Manuel Bustillo 622128a29a
Some checks failed
Run unit tests / copyright_notice (pull_request) Successful in 2m9s
Run unit tests / rubocop (pull_request) Failing after 2m42s
Run unit tests / check-licenses (pull_request) Successful in 2m58s
Run unit tests / unit_tests (pull_request) Failing after 4m14s
Run unit tests / build-static-assets (pull_request) Has been skipped
Add copyright notice
2025-06-01 15:59:18 +00:00

45 lines
1.1 KiB
Ruby

# 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