Created
May 20, 2018 13:34
-
-
Save AndrewDryga/4cb06e5443acb181dfba1fefa5b177fc to your computer and use it in GitHub Desktop.
Sage: DDD
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
defmodule BookingApp.Booker do | |
alias BookingApp.{Billing, Users, Hotels, Cars, Flights, Repo} | |
def create_booking(attrs) do | |
Sage.new() | |
|> Billing.authorize_card(attrs) | |
|> Hotels.maybe_book_hotel(attrs) | |
|> Cars.maybe_book_car(attrs) | |
|> Flights.maybe_book_flight(attrs) | |
|> Users.sign_up() | |
|> Billing.charge_card() | |
|> Sage.transaction(Repo, attrs) | |
end | |
end |
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
defmodule BookingApp.Hotels do | |
def maybe_book_hotel(%Sage{} = sage, %{"hotel" => hotel}) do | |
Sage.run_async(sage, :book_hotel, &book/2, &cancel_booking/4) | |
end | |
def maybe_book_hotel(%Sage{} = sage, _attrs) do | |
sage | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment