Class: Yes::Command::Api::V1::CommandsController

Inherits:
ActionController::API
  • Object
show all
Includes:
Yes::Core::OpenTelemetry::Trackable
Defined in:
app/controllers/yes/command/api/v1/commands_controller.rb

Overview

Controller for executing command batches via the command bus.

Auth is delegated to the configured auth adapter in Yes::Core.configuration. If no auth adapter is configured, authentication will raise an error.

Constant Summary collapse

MAX_INLINE_COMMANDS_PER_REQ =
10

Instance Method Summary collapse

Instance Method Details

#executeObject

Executes a batch of commands.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/yes/command/api/v1/commands_controller.rb', line 43

def execute
  Yes::Command::Api::Commands::ParamsValidator.call(params[:commands])
  deserialize_commands = Yes::Command::Api::Commands::Deserializer.call(params[:commands])
  expanded_commands = expand_commands(deserialize_commands)
  return too_many_inline_commands if perform_inline? && expanded_commands.size > MAX_INLINE_COMMANDS_PER_REQ

  Yes::Command::Api::Commands::BatchAuthorizer.call(expanded_commands, auth_data)
  Yes::Command::Api::Commands::BatchValidator.call(expanded_commands)
  cmd_bus_response = command_bus.call(
    (deserialize_commands),
    notifier_options: { channel: @channel }
  )

  render json: success_response_data(cmd_bus_response), status: :ok
end