2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-12-28 18:37:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-07-25 10:47:49 +02:00
|
|
|
require 'csv'
|
|
|
|
|
2024-07-11 20:08:26 +02:00
|
|
|
class GuestsController < ApplicationController
|
|
|
|
def index
|
2024-12-28 18:28:28 +01:00
|
|
|
render json: Guest.includes(:group)
|
2024-12-08 13:10:49 +01:00
|
|
|
.left_joins(:group)
|
2024-11-16 02:16:19 +01:00
|
|
|
.order('groups.name' => :asc, name: :asc)
|
|
|
|
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
|
2024-07-11 20:08:26 +02:00
|
|
|
end
|
|
|
|
|
2024-11-17 11:47:12 +01:00
|
|
|
def create
|
2024-11-17 20:01:23 +01:00
|
|
|
Guest.create!(guest_params)
|
2024-11-17 11:47:12 +01:00
|
|
|
render json: {}, status: :created
|
|
|
|
end
|
|
|
|
|
2024-11-11 07:43:42 +01:00
|
|
|
def update
|
2024-11-17 20:01:23 +01:00
|
|
|
Guest.find(params[:id]).update!(guest_params)
|
2024-10-27 14:03:13 +01:00
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
2024-11-17 18:24:43 +01:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
Guest.find(params[:id]).destroy!
|
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
2024-11-17 20:01:23 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def guest_params
|
|
|
|
params.require(:guest).permit(:name, :group_id, :status)
|
|
|
|
end
|
2024-07-11 20:08:26 +02:00
|
|
|
end
|