Compare commits

..

No commits in common. "c0ba659f29cc1719ab2014b20a1d9af9f58f4aa0" and "9461fa5255f1d32f9274437b06aff90707baaf49" have entirely different histories.

2 changed files with 10 additions and 7 deletions

View File

@ -5,22 +5,21 @@
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)
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
end
def create
guest = Guest.create!(guest_params)
render json: guest.as_json(GUEST_PARAMS), status: :created
Guest.create!(guest_params)
render json: {}, status: :created
end
def update
guest = Guest.find(params[:id]).update!(guest_params)
render json: guest.as_json(GUEST_PARAMS), status: :ok
Guest.find(params[:id]).update!(guest_params)
render json: {}, status: :ok
end
def destroy

View File

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