WEBVTT

00:00:00.500 --> 00:00:02.791
Branches keeps no fields of its own.

00:00:03.692 --> 00:00:07.559
It keeps a map of child modules, one inventory per branch number.

00:00:08.457 --> 00:00:11.465
Opening branch nine checks that the branch is new and that the

00:00:11.478 --> 00:00:13.223
Shop has fewer than thirty-two.

00:00:14.121 --> 00:00:17.311
Then it creates an inventory and attaches it under key nine.

00:00:18.210 --> 00:00:21.621
To stock an item, Branches finds the inventory for that branch

00:00:21.634 --> 00:00:23.015
and calls its put method.

00:00:23.913 --> 00:00:26.778
Branches cannot see inside the inventory's data.

00:00:27.676 --> 00:00:30.944
Inventory checks its own limit and saves item forty-four at

00:00:30.957 --> 00:00:32.910
price one hundred with eight in stock.

00:00:35.033 --> 00:00:38.210
Checkout saves nothing, so it has no memory folder.

00:00:39.110 --> 00:00:42.027
Its service lists the two services it depends on.

00:00:42.925 --> 00:00:46.180
The root builds Branches and Settings once and hands the same

00:00:46.193 --> 00:00:47.222
two to Checkout.

00:00:49.333 --> 00:00:53.017
A customer checks out three units of item forty-four from branch

00:00:53.030 --> 00:00:53.486
nine.

00:00:54.387 --> 00:00:57.551
The endpoint opens one write scope and calls buy.

00:00:58.449 --> 00:01:01.223
Everything that follows happens inside that one scope.

00:01:02.121 --> 00:01:04.269
Buy first asks Branches for a quote.

00:01:05.168 --> 00:01:08.566
Branches passes the question to the inventory for branch nine.

00:01:09.465 --> 00:01:10.754
Quote only reads.

00:01:11.652 --> 00:01:15.220
Eight are in stock, so three at one hundred gives three hundred.

00:01:16.118 --> 00:01:19.751
Next it reads the tax from Settings, which is five hundred basis

00:01:19.764 --> 00:01:20.324
points.

00:01:21.223 --> 00:01:22.785
The arithmetic is checked.

00:01:23.684 --> 00:01:25.988
A total that does not fit returns None.

00:01:26.887 --> 00:01:29.256
Here the total is three hundred and fifteen.

00:01:30.155 --> 00:01:32.421
Only now does checkout ask for the sale.

00:01:33.319 --> 00:01:36.262
Inventory checks the quantity once more and takes three from

00:01:36.275 --> 00:01:36.717
stock.

00:01:37.616 --> 00:01:38.618
Five remain.

00:01:39.517 --> 00:01:43.085
Checkout returns three hundred and fifteen and the scope closes.

00:01:43.983 --> 00:01:45.689
The test then asks for six.

00:01:46.587 --> 00:01:49.973
Five are left, so the quote comes back empty and buy returns

00:01:49.986 --> 00:01:52.160
None before it reads tax or sells.

00:01:53.059 --> 00:01:54.230
This order matters.

00:01:55.129 --> 00:01:58.371
A returned refusal does not undo a write that already happened,

00:01:58.592 --> 00:01:59.960
so the checks come first.

00:02:02.100 --> 00:02:04.795
Closing a branch takes its inventory out of the map.

00:02:05.695 --> 00:02:09.237
Nothing attaches it anywhere else, so it is gone when the scope

00:02:09.250 --> 00:02:09.706
ends.

00:02:10.604 --> 00:02:14.094
Opening branch nine again creates a new, empty inventory.

00:02:14.992 --> 00:02:17.154
Item forty-four is no longer there.

