28 lines
728 B
Ruby
28 lines
728 B
Ruby
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
require 'csv'
|
|
|
|
class GuestsController < ApplicationController
|
|
def index
|
|
render json: Guest.all.includes(:group)
|
|
.joins(:group)
|
|
.order('groups.name' => :asc, name: :asc)
|
|
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
|
|
end
|
|
|
|
def create
|
|
Guest.create!(params.require(:guest).permit(:name, :group_id, :status))
|
|
render json: {}, status: :created
|
|
end
|
|
|
|
def update
|
|
Guest.find(params[:id]).update!(params.require(:guest).permit(:name, :status))
|
|
render json: {}, status: :ok
|
|
end
|
|
|
|
def destroy
|
|
Guest.find(params[:id]).destroy!
|
|
render json: {}, status: :ok
|
|
end
|
|
end
|