Compare commits
4 Commits
cb0e387c3a
...
80c1c9b99d
Author | SHA1 | Date | |
---|---|---|---|
80c1c9b99d | |||
1f81dabff4 | |||
f1d1ea825c | |||
7542c6361c |
@ -11,12 +11,23 @@ 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
|
||||
|
||||
def destroy
|
||||
Guest.find(params[:id]).destroy!
|
||||
render json: {}, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def guest_params
|
||||
params.require(:guest).permit(:name, :group_id, :status)
|
||||
end
|
||||
end
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
@ -77,5 +78,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user