WEBVTT

00:00.020 --> 00:04.910
Okay, so now we've successfully set up our payment system in the previous section so we can make that

00:04.910 --> 00:07.460
payment from client browser to stripe.

00:07.460 --> 00:10.820
But we need to think about what's going to happen on our API side.

00:10.820 --> 00:16.580
Because at the moment we don't have an order being created on our API, so nobody's going to deliver

00:16.580 --> 00:19.130
the fake products that they have ordered.

00:19.130 --> 00:21.980
And we need to deal with that in this section.

00:21.980 --> 00:24.020
So we're going to start looking at orders.

00:24.020 --> 00:31.040
And when somebody makes a payment, then we need to create the corresponding order in our API server.

00:31.040 --> 00:33.110
So let's go take a look at doing that.

00:33.110 --> 00:37.220
And we're going to start with creating some entities for this.

00:37.250 --> 00:41.000
Now our order is going to be a combination of several things.

00:41.000 --> 00:41.600
Really.

00:41.600 --> 00:45.860
It's going to be the order itself that's going to have details about the order items.

00:45.860 --> 00:48.980
We're also going to need to track the shipping address.

00:48.980 --> 00:54.590
Possibly we want to store the payment summary, the card that was used, not the full card, just the

00:54.590 --> 01:02.120
last four digits, the expiry date and the brand similar to what we displayed in the payment review

01:02.120 --> 01:05.030
and would also need things like an order status as well.

01:05.030 --> 01:08.150
So we have several different elements that make up the order.

01:08.150 --> 01:16.280
And the common practice is to create a new folder for something like this and we'll call it order aggregate,

01:17.030 --> 01:20.270
an aggregate of everything that makes up an order.

01:20.270 --> 01:28.070
And inside our new order aggregate folder we'll create a new file and I'll call this one just in fact

01:28.070 --> 01:29.090
I'll call it shipping address.

01:29.090 --> 01:35.720
Just to be very clear, it's not the same as the other address that we're storing with the user information

01:35.720 --> 01:36.830
effectively.

01:36.860 --> 01:39.170
And that needs to be a class.

01:39.170 --> 01:42.980
So I need to select class and then I can use shipping address.

01:43.010 --> 01:49.040
Now this is going to be very similar to the address entity but with one crucial difference in that we're

01:49.040 --> 01:51.530
not going to store the ID with the address.

01:51.530 --> 01:53.720
It's going to be part of the order.

01:53.720 --> 02:00.450
And what we refer to this as is an owned entity, because it's going to be part of the order table,

02:00.450 --> 02:02.670
but it is a separate entity in itself.

02:02.670 --> 02:05.640
And I'll demonstrate what I mean by that very soon.

02:05.670 --> 02:12.420
So the properties for this address, I'm just going to copy everything apart from the ID, and I'm going

02:12.450 --> 02:18.720
to go to the shipping address and paste in those properties inside here and just do a bit of reformatting.

02:18.720 --> 02:22.590
And we need the JSON property name to stay as postal code as well.

02:22.590 --> 02:27.780
So I'll just bring in system text JSON serialization to handle that.

02:28.050 --> 02:31.920
Now we're going to use something that's referred to in here as an owned property.

02:31.920 --> 02:35.460
And we do that by giving this an attribute as owned.

02:35.460 --> 02:42.780
And this shipping address will not have its own table in our database, but it's going to be in line

02:42.780 --> 02:44.400
with an order.

02:44.730 --> 02:47.850
So this is going to make more sense when we see it in action.

02:47.850 --> 02:55.290
But for now, an owned property doesn't need an ID and we use the owned attribute inside here.

02:55.890 --> 03:01.130
The next thing we'll add in our order aggregate folder, we'll create another new file and we'll create

03:01.130 --> 03:01.910
another class.

03:01.910 --> 03:05.450
And we'll call this one product item ordered.

03:05.600 --> 03:13.010
And inside here we will have a prop that's an int and we'll call it product ID.

03:14.480 --> 03:17.990
We'll have a prop that's a string.

03:18.980 --> 03:21.080
And this will be for the name of the product.

03:21.080 --> 03:25.790
And we'll have a prop that's a string of the picture you URL.

03:25.850 --> 03:30.680
And we'll make the name and picture URL required as well.

03:31.130 --> 03:34.220
This is going to be another owned property.

03:34.370 --> 03:41.450
So our orders are going to have a one to many relationship with an order item that we have yet to create.

03:41.450 --> 03:46.640
And inside that order item we're going to track the product item ordered.

03:46.940 --> 03:53.780
And this is really just a historical snapshot of the item that they ordered when they made this particular

03:53.780 --> 03:54.560
order.

03:54.560 --> 04:00.450
So the name could change slightly Or the picture URL could be updated to something else, but we'll

04:00.450 --> 04:06.270
keep the original picture URL that was provided when the user made that order.

04:06.270 --> 04:12.750
And once again, even though we do technically have an ID here, we're going to make this an owned property

04:12.750 --> 04:13.620
as well.

04:13.620 --> 04:17.070
And this is going to be owned by the order item.

04:17.100 --> 04:21.690
Another thing that we'll have inside our order aggregates is the order status.

04:21.690 --> 04:23.280
So I'm going to create another new file.

04:23.280 --> 04:26.100
And this one's going to be an enum type.

04:26.820 --> 04:29.850
And we'll call this order status.

04:30.600 --> 04:34.440
And inside here we're going to have various statuses.

04:34.440 --> 04:40.260
So we'll have a pending status for whilst we're waiting for payment for this order we'll have a payment

04:40.560 --> 04:46.350
received and we'll have a payment failed.

04:46.740 --> 04:50.700
And we may come back and add more statuses as we need them.

04:50.700 --> 04:55.350
But we won't have things like shipped because we're not really going to implement some kind of delivery

04:55.350 --> 05:02.640
system where a fake delivery driver comes up and picks up our fake orders from the fake warehouse that

05:02.640 --> 05:03.480
we simply don't have.

05:03.510 --> 05:04.590
We're not going to go that far.

05:04.620 --> 05:05.820
Of course, that would be silly.

05:05.820 --> 05:10.320
So we'll just stick with these for now, and we'll come back and add more if we need to.

05:10.350 --> 05:14.400
And the next one we'll create will create an order item.

05:14.400 --> 05:15.690
So this is going to be a class.

05:15.690 --> 05:18.210
And we'll say order item.

05:19.110 --> 05:26.130
And inside this class we'll have a prop that's an int that's called ID.

05:26.850 --> 05:32.130
We'll have a prop that's going to be the product item ordered.

05:32.130 --> 05:38.070
And we'll just call this item ordered and we'll make this required.

05:38.070 --> 05:43.140
We don't want an order item without the product item ordered.

05:43.170 --> 05:46.620
We'll have a prop that's going to be a long for the price.

05:47.160 --> 05:50.760
And we'll also have the prop that's an int for the quantity.

05:50.760 --> 05:53.700
And we'll add another class inside our order.

05:53.730 --> 05:55.290
Aggregate another new file.

05:55.290 --> 05:59.010
And this is going to be a class and we'll call it payment summary.

05:59.700 --> 06:09.600
Inside this class we will have a prop that's an int for the last four of the cards.

06:09.600 --> 06:21.390
We'll have a prop that's a string for the brand, a prop that's an int for the experiment for the expiry

06:21.420 --> 06:25.980
month, and a prop that's an int for the exp year.

06:26.010 --> 06:28.710
And we'll make the brand required.

06:29.550 --> 06:33.000
And we'll also make this an owned property.

06:33.000 --> 06:35.880
And it's going to be an owned property by the order.

06:35.880 --> 06:38.280
So we'll make this owned as well.

06:38.310 --> 06:43.560
So these are all of the different elements that are going to make up our order aggregate without the

06:43.560 --> 06:45.330
actual order itself.

06:45.780 --> 06:50.340
And because we've got quite a few classes to create in this section, I'll split this into two parts.

06:50.340 --> 06:54.960
And next we'll take a look at creating the order entity itself.
