Return guest that has just been created
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

This commit is contained in:
Manuel Bustillo 2025-06-08 17:38:34 +02:00
parent 9461fa5255
commit 4a107d6728
2 changed files with 7 additions and 10 deletions

View File

@ -5,21 +5,22 @@
require 'csv' require 'csv'
class GuestsController < ApplicationController class GuestsController < ApplicationController
GUEST_PARAMS = { only: %i[id name status], include: { group: { only: %i[id name] } } }.freeze
def index def index
render json: Guest.includes(:group) render json: Guest.includes(:group)
.left_joins(:group) .left_joins(:group)
.order('groups.name' => :asc, name: :asc) .order('groups.name' => :asc, name: :asc)
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } }) .as_json(GUEST_PARAMS)
end end
def create def create
Guest.create!(guest_params) guest = Guest.create!(guest_params)
render json: {}, status: :created render json: guest.as_json(GUEST_PARAMS), status: :created
end end
def update def update
Guest.find(params[:id]).update!(guest_params) guest = Guest.find(params[:id]).update!(guest_params)
render json: {}, status: :ok render json: guest.as_json(GUEST_PARAMS), status: :ok
end end
def destroy def destroy

View File

@ -5,16 +5,12 @@
class SerializableGuest < JSONAPI::Serializable::Resource class SerializableGuest < JSONAPI::Serializable::Resource
type 'guest' type 'guest'
attributes :id, :group_id, :status attributes :id, :status
attribute :name do attribute :name do
@object.name @object.name
end end
attribute :group_name do
@object.group.name
end
attribute :status do attribute :status do
@object.status.capitalize @object.status.capitalize
end end