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
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:
commit
c0ba659f29
@ -5,21 +5,22 @@
|
||||
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(only: %i[id name status], include: { group: { only: %i[id name] } })
|
||||
.as_json(GUEST_PARAMS)
|
||||
end
|
||||
|
||||
def create
|
||||
Guest.create!(guest_params)
|
||||
render json: {}, status: :created
|
||||
guest = Guest.create!(guest_params)
|
||||
render json: guest.as_json(GUEST_PARAMS), status: :created
|
||||
end
|
||||
|
||||
def update
|
||||
Guest.find(params[:id]).update!(guest_params)
|
||||
render json: {}, status: :ok
|
||||
guest = Guest.find(params[:id]).update!(guest_params)
|
||||
render json: guest.as_json(GUEST_PARAMS), status: :ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -5,16 +5,12 @@
|
||||
class SerializableGuest < JSONAPI::Serializable::Resource
|
||||
type 'guest'
|
||||
|
||||
attributes :id, :group_id, :status
|
||||
attributes :id, :status
|
||||
|
||||
attribute :name do
|
||||
@object.name
|
||||
end
|
||||
|
||||
attribute :group_name do
|
||||
@object.group.name
|
||||
end
|
||||
|
||||
attribute :status do
|
||||
@object.status.capitalize
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user