Class: CoPlan::Api::V1::OperationsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/coplan/api/v1/operations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/coplan/api/v1/operations_controller.rb', line 8

def create
  operations = params[:operations]
  base_revision = params[:base_revision]&.to_i

  unless base_revision.present?
    render json: { error: "base_revision is required" }, status: :unprocessable_entity
    return
  end

  unless operations.is_a?(Array) && operations.any?
    render json: { error: "operations must be a non-empty array" }, status: :unprocessable_entity
    return
  end

  if params[:session_id].present?
    apply_with_session(operations, base_revision)
  elsif params[:lease_token].present?
    apply_with_lease(operations, base_revision)
  else
    apply_direct(operations, base_revision)
  end
rescue Plans::OperationError => e
  render json: { error: e.message }, status: :unprocessable_entity
end