Remove unused bulk update endpoint
This commit is contained in:
parent
29c9764450
commit
31d41ea2ea
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user