wedding-planner/app/controllers/guests_controller.rb
Manuel Bustillo 4a107d6728
All checks were successful
Run unit tests / copyright_notice (pull_request) Successful in 40s
Run unit tests / rubocop (pull_request) Successful in 1m2s
Run unit tests / unit_tests (pull_request) Successful in 1m39s
Run unit tests / check-licenses (pull_request) Successful in 34s
Run unit tests / build-static-assets (pull_request) Successful in 21m2s
Return guest that has just been created
2025-06-08 17:38:34 +02:00

37 lines
900 B
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
def index
render json: Guest.includes(:group)
.left_joins(:group)
.order('groups.name' => :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]).update!(guest_params)
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
params.expect(guest: %i[name group_id status])
end
end