diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 1b51eaf..03cf377 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -19,4 +19,9 @@ class GuestsController < ApplicationController 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 diff --git a/app/models/guest.rb b/app/models/guest.rb index bf689d9..40c41be 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -36,6 +36,9 @@ class Guest < ApplicationRecord scope :potential, -> { where.not(status: %i[declined considered]) } after_save :recalculate_simulations, if: :saved_change_to_status? + after_destroy :recalculate_simulations + + has_many :seats, dependent: :delete_all private diff --git a/config/routes.rb b/config/routes.rb index b90eb65..c9d7ee6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ Rails.application.routes.draw do mount Rswag::Ui::Engine => '/api-docs' mount Rswag::Api::Engine => '/api-docs' resources :groups, only: :index - resources :guests, only: %i[index create update] do + resources :guests, only: %i[index create update destroy] do post :bulk_update, on: :collection end resources :expenses, only: %i[index update] do diff --git a/spec/requests/guests_spec.rb b/spec/requests/guests_spec.rb index ea6ae59..0bbfe7a 100644 --- a/spec/requests/guests_spec.rb +++ b/spec/requests/guests_spec.rb @@ -77,5 +77,14 @@ RSpec.describe 'guests', type: :request do response_422 response_404 end + + delete('delete guest') do + tags 'Guests' + produces 'application/json' + parameter name: 'id', in: :path, type: :string, format: :uuid + + response_empty_200 + response_404 + end end end