From 80c1c9b99d8309370ab8082249a621035c2c7c46 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 17 Nov 2024 20:01:23 +0100 Subject: [PATCH] Refine guest controller --- app/controllers/guests_controller.rb | 10 ++++++++-- spec/requests/guests_spec.rb | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 03cf377..a302541 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -11,12 +11,12 @@ class GuestsController < ApplicationController end def create - Guest.create!(params.require(:guest).permit(:name, :group_id, :status)) + Guest.create!(guest_params) render json: {}, status: :created end def update - Guest.find(params[:id]).update!(params.require(:guest).permit(:name, :status)) + Guest.find(params[:id]).update!(guest_params) render json: {}, status: :ok end @@ -24,4 +24,10 @@ class GuestsController < ApplicationController Guest.find(params[:id]).destroy! render json: {}, status: :ok end + + private + + def guest_params + params.require(:guest).permit(:name, :group_id, :status) + end end diff --git a/spec/requests/guests_spec.rb b/spec/requests/guests_spec.rb index 0bbfe7a..df26f17 100644 --- a/spec/requests/guests_spec.rb +++ b/spec/requests/guests_spec.rb @@ -67,6 +67,7 @@ RSpec.describe 'guests', type: :request do type: :object, properties: { name: { type: :string }, + group_id: { type: :string, format: :uuid }, status: { type: :string, enum: Guest.statuses.keys } } }