Created
March 21, 2020 16:36
-
-
Save joegaudet/8d89c0820ad90deada29bfc5f1d8ce24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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