Powered by AppSignal & Oban Pro

Lesson 02 Livebook: Planetary Law

livebooks/02_planetary_law.livemd

Lesson 02 Livebook: Planetary Law

This notebook keeps chapter 2 focused on the first route-aware GTA rule:

> a manifest can be globally valid and still fail the route

Mix.install([
  {:galactic_trade_authority, path: "../02_planetary_law"}
])

Build A Taxed Shipment

state = GalacticTradeAuthority.bootstrap_registry!()

%{
  manifest: state.shipment.manifest_number,
  route: {state.origin_planet.name, state.destination_planet.name},
  tax_due: state.shipment.tax_due,
  classification: state.shipment.route_classification,
  summary: state.shipment.compliance_summary
}

Inspect A Blocked Route

try do
  GalacticTradeAuthority.Resources.Shipment.register!(%{
    manifest_number: "GTA-2002",
    quantity: 4,
    declared_value: 12_000,
    trader_id: state.trader.id,
    origin_planet_id: state.origin_planet.id,
    destination_planet_id: state.blocked_planet.id,
    resource_id: state.blocked_resource.id
  })
rescue
  error in Ash.Error.Invalid ->
    error.errors
    |> Enum.map(&Exception.message/1)
end

The registry now has to ask where the cargo is going before it can decide whether the shipment is real at all.