Compare commits

...

4 Commits

Author SHA1 Message Date
80c1c9b99d Refine guest controller
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 1m26s
Add copyright notice / copyright_notice (pull_request) Successful in 2m19s
Run unit tests / unit_tests (pull_request) Successful in 3m39s
2024-11-17 20:02:08 +01:00
1f81dabff4 Merge pull request 'Define an endpoint to remove guests' (#139) from delete-guest-endpoint into main
Some checks failed
Check usage of free licenses / check-licenses (push) Successful in 1m4s
Run unit tests / unit_tests (push) Successful in 3m42s
Build Nginx-based docker image / build-static-assets (push) Failing after 17m24s
Reviewed-on: #139
2024-11-17 17:28:13 +00:00
f1d1ea825c Recalculate simulations after removing a guest
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 56s
Add copyright notice / copyright_notice (pull_request) Successful in 1m20s
Run unit tests / unit_tests (pull_request) Successful in 2m4s
2024-11-17 18:25:38 +01:00
7542c6361c Define an endpoint to destroy guests 2024-11-17 18:24:43 +01:00
4 changed files with 27 additions and 3 deletions

View File

@ -11,12 +11,23 @@ class GuestsController < ApplicationController
end end
def create def create
Guest.create!(params.require(:guest).permit(:name, :group_id, :status)) Guest.create!(guest_params)
render json: {}, status: :created render json: {}, status: :created
end end
def update def update
Guest.find(params[:id]).update!(params.require(:guest).permit(:name, :status)) Guest.find(params[:id]).update!(guest_params)
render json: {}, status: :ok render json: {}, status: :ok
end 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 end

View File

@ -36,6 +36,9 @@ class Guest < ApplicationRecord
scope :potential, -> { where.not(status: %i[declined considered]) } scope :potential, -> { where.not(status: %i[declined considered]) }
after_save :recalculate_simulations, if: :saved_change_to_status? after_save :recalculate_simulations, if: :saved_change_to_status?
after_destroy :recalculate_simulations
has_many :seats, dependent: :delete_all
private private

View File

@ -4,7 +4,7 @@ Rails.application.routes.draw do
mount Rswag::Ui::Engine => '/api-docs' mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs' mount Rswag::Api::Engine => '/api-docs'
resources :groups, only: :index 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 post :bulk_update, on: :collection
end end
resources :expenses, only: %i[index update] do resources :expenses, only: %i[index update] do

View File

@ -67,6 +67,7 @@ RSpec.describe 'guests', type: :request do
type: :object, type: :object,
properties: { properties: {
name: { type: :string }, name: { type: :string },
group_id: { type: :string, format: :uuid },
status: { type: :string, enum: Guest.statuses.keys } status: { type: :string, enum: Guest.statuses.keys }
} }
} }
@ -77,5 +78,14 @@ RSpec.describe 'guests', type: :request do
response_422 response_422
response_404 response_404
end 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
end end