Merge pull request 'Return guest that has just been created' (#272) from api/return-guest into main
Some checks failed
Run unit tests / rubocop (push) Successful in 41s
Run unit tests / check-licenses (push) Successful in 53s
Run unit tests / copyright_notice (push) Successful in 1m8s
Run unit tests / unit_tests (push) Successful in 3m2s
Run unit tests / build-static-assets (push) Has been cancelled

Reviewed-on: #272
This commit is contained in:
bustikiller 2025-06-08 21:31:40 +00:00
commit c0ba659f29
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