Remove unused bulk update endpoint
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 1m39s
Add copyright notice / copyright_notice (pull_request) Successful in 2m48s
Run unit tests / unit_tests (pull_request) Successful in 3m46s

This commit is contained in:
Manuel Bustillo 2024-11-17 17:07:29 +01:00
parent 29c9764450
commit 31d41ea2ea
4 changed files with 13 additions and 55 deletions

View File

@ -16,12 +16,7 @@ class GuestsController < ApplicationController
end
def update
Guest.find(params[:id]).update!(params.require(:guest).permit(:name))
render json: {}, status: :ok
end
def bulk_update
Guests::UpdateUseCase.new(guest_ids: params[:guest_ids], params: params.require(:properties).permit(:status)).call
Guest.find(params[:id]).update!(params.require(:guest).permit(:name, :status))
render json: {}, status: :ok
end
end

View File

@ -34,4 +34,14 @@ class Guest < ApplicationRecord
validates :name, presence: true
scope :potential, -> { where.not(status: %i[declined considered]) }
after_save :recalculate_simulations, if: :saved_change_to_status?
private
def recalculate_simulations
TablesArrangement.delete_all
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new })
end
end

View File

@ -1,22 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
module Guests
class UpdateUseCase
private attr_reader :guest_ids, :params
def initialize(guest_ids:, params:)
@guest_ids = guest_ids
@params = params
end
def call
Guest.where(id: guest_ids).update!(params)
# TODO: Not all status transitions may require a table re-arrangement
return unless params.key?(:status)
TablesArrangement.delete_all
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new })
end
end
end

View File

@ -3,31 +3,6 @@
require 'swagger_helper'
RSpec.describe 'guests', type: :request do
path '/guests/bulk_update' do
post('Update multiple guests in a single request') do
tags 'Guests'
consumes 'application/json'
produces 'application/json'
parameter name: :body, in: :body, schema: {
type: :object,
required: %i[guest_ids properties],
properties: {
guest_ids: { type: :array, items: { type: :string, format: :uuid } },
properties: {
type: :object,
required: %i[status],
properties: {
status: { type: :string, enum: Guest.statuses.keys }
}
}
}
}
response_empty_200
response_422
end
end
path '/guests' do
get('list guests') do
tags 'Guests'
@ -90,9 +65,9 @@ RSpec.describe 'guests', type: :request do
properties: {
guest: {
type: :object,
required: %i[name],
properties: {
name: { type: :string }
name: { type: :string },
status: { type: :string, enum: Guest.statuses.keys }
}
}
}