From 31d41ea2ea01a5feaadd44d25cc1621f5e1f8632 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 17 Nov 2024 17:07:29 +0100 Subject: [PATCH] Remove unused bulk update endpoint --- app/controllers/guests_controller.rb | 7 +----- app/models/guest.rb | 10 +++++++++ app/use_cases/guests/update_use_case.rb | 22 ------------------- spec/requests/guests_spec.rb | 29 ++----------------------- 4 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 app/use_cases/guests/update_use_case.rb diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 9a0c9fb..1b51eaf 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -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 diff --git a/app/models/guest.rb b/app/models/guest.rb index 8e794f2..bf689d9 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -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 diff --git a/app/use_cases/guests/update_use_case.rb b/app/use_cases/guests/update_use_case.rb deleted file mode 100644 index 3d82c52..0000000 --- a/app/use_cases/guests/update_use_case.rb +++ /dev/null @@ -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 diff --git a/spec/requests/guests_spec.rb b/spec/requests/guests_spec.rb index a7f637c..ea6ae59 100644 --- a/spec/requests/guests_spec.rb +++ b/spec/requests/guests_spec.rb @@ -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 } } } }