Skip to content

Instantly share code, notes, and snippets.

@AndrewDryga
Created May 20, 2018 13:34
Show Gist options
  • Save AndrewDryga/4cb06e5443acb181dfba1fefa5b177fc to your computer and use it in GitHub Desktop.
Save AndrewDryga/4cb06e5443acb181dfba1fefa5b177fc to your computer and use it in GitHub Desktop.
Sage: DDD
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
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