Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Created March 21, 2020 16:36
Show Gist options
  • Save joegaudet/8d89c0820ad90deada29bfc5f1d8ce24 to your computer and use it in GitHub Desktop.
Save joegaudet/8d89c0820ad90deada29bfc5f1d8ce24 to your computer and use it in GitHub Desktop.
module Ordering
module Commands
module States
class Cancel < ::Commands::Command
dependency :find_order, ::Queries::Id.klass(Order)
dependency :free_utilization, RestaurantCapacities::FreeUtilizationService
dependency :cancel_sync, ThirdPartyLogistics::CancelSync
dependency :emit, ::Events::Emitter
def call(order_id)
order = find_order.(order_id)
in_transaction do
order.cancel!
free_utilization.(order)
cancel_sync.(order)
end
emit.(Ordering::Events::Cancelled.(id: order.id))
order
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment