Some checks failed
Run unit tests / copyright_notice (pull_request) Successful in 57s
Run unit tests / check-licenses (pull_request) Failing after 2m13s
Run unit tests / rubocop (pull_request) Failing after 3m35s
Run unit tests / unit_tests (pull_request) Failing after 5m6s
Run unit tests / build-static-assets (pull_request) Has been skipped
43 lines
1.0 KiB
Ruby
43 lines
1.0 KiB
Ruby
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
|