WEBVTT

00:00.020 --> 00:06.200
Okay, hopefully you gave this a go to populate the code we need in the remove basket item.

00:06.200 --> 00:09.350
I'll just run through what the approach to this is.

00:09.350 --> 00:15.290
Anyway, it's a fairly quick method that we need to create here because we've got most of the code.

00:15.290 --> 00:22.100
We need all the reusable code we kind of need anyway, certainly in regards to the getting of the basket.

00:22.100 --> 00:27.590
So I'll specify var basket equals await and retrieve basket.

00:27.590 --> 00:28.820
That's the first step.

00:28.820 --> 00:32.180
And then we need to remove the item or reduce its quantity.

00:32.180 --> 00:37.520
And again this is something that we've already created in our basket entity.

00:37.520 --> 00:42.800
But before we get to that we need to make sure the basket is not equal to null.

00:42.800 --> 00:45.590
So I'm going to check to see if the basket is equal to null.

00:45.590 --> 00:56.990
And if it is, I'm going to return a bad request and say unable to retrieve baskets as we cannot remove

00:56.990 --> 01:03.140
an item from a basket if we do not have that basket, the next step is to actually remove the item.

01:03.140 --> 01:08.720
And because we already created this helper method in our entity, it's just a matter of using basket

01:08.720 --> 01:12.320
remove item and then in the remove item.

01:12.320 --> 01:17.960
If you're wondering what properties you need to send for a specific method because you created it some

01:17.960 --> 01:21.500
time ago, it's got many different arguments that you need to pass.

01:21.500 --> 01:25.820
Then just open up some new parentheses and then press escape.

01:25.820 --> 01:30.410
And then this will give you the documentation about what arguments this method accepts.

01:30.410 --> 01:33.350
So we need a product ID and we need a quantity.

01:33.350 --> 01:37.880
And when we've got our arguments in parentheses like this ordering is important.

01:37.880 --> 01:43.250
We need the product ID to be first and we need the quantity ID second.

01:44.240 --> 01:48.800
So in this case we'll specify the product ID and then the quantity.

01:49.340 --> 01:50.990
And then we can save changes.

01:50.990 --> 01:59.990
So I'm just going to copy the code I have here the var results and save those changes.

02:00.140 --> 02:06.570
And then we can check the results and say if Results.

02:06.600 --> 02:08.070
Is effectively true.

02:08.100 --> 02:10.170
Then we're going to return okay.

02:10.200 --> 02:16.050
Which is the correct response to send back for an HTTP delete method if it was successful.

02:16.080 --> 02:24.060
Otherwise, we're going to return a bad request and say problem updating baskets.

02:24.810 --> 02:25.830
So great.

02:26.580 --> 02:28.680
That is now our remove method.

02:28.680 --> 02:36.450
And if I just open up the terminal and it says file updated, I'm going to see if Hot Reload has worked

02:36.450 --> 02:37.680
for this one.

02:37.680 --> 02:43.170
So let's go back to postman and I'll click on the remove the item from the basket.

02:43.170 --> 02:45.300
So product ID of two quantity of one.

02:45.330 --> 02:52.620
If I take a look at what I currently have for the basket and click send and where's my response gone.

02:52.620 --> 02:54.090
It's hidden down here.

02:54.090 --> 02:57.570
So I've currently got a quantity of two for the product ID of two.

02:57.600 --> 02:59.430
I'd expect that to go down to one.

02:59.460 --> 03:03.330
So if I click on this request and click send I get the 200.

03:03.360 --> 03:03.660
Okay.

03:03.690 --> 03:05.070
There's no more details in this.

03:05.070 --> 03:06.330
That's what we'd expect.

03:06.330 --> 03:09.870
So I'm going to need to get the basket again to make sure that it has been updated.

03:09.870 --> 03:17.280
I'll click send and something did not work because that quantity is still two.

03:17.460 --> 03:20.490
And yeah, it's still two.

03:21.570 --> 03:23.070
And what went wrong?

03:23.070 --> 03:25.350
There is my question.

03:25.500 --> 03:27.090
So let's head back to VS code.

03:27.090 --> 03:33.030
I did say that was relatively simple, but what I didn't do, and this is no doubt the problem.

03:33.060 --> 03:37.500
The first troubleshooting step always, always restart the API server.

03:37.500 --> 03:40.500
I thought I'd see if hot reload would accommodate that change.

03:40.500 --> 03:43.740
It doesn't look like it has or it could be the reason.

03:43.740 --> 03:48.060
So I'm just going to restart the API server and see if that does fix the problem.

03:48.060 --> 03:50.580
So I'll go back to postman.

03:50.610 --> 03:56.880
I'll click send again for the remove item from basket and we get the 200.

03:56.910 --> 03:57.240
Okay.

03:57.270 --> 04:00.780
Again, if I go and get the basket I'd like to see that quantity reduced to one.

04:00.780 --> 04:05.640
I'll click send and sure enough it has indeed gone down to one.

04:05.640 --> 04:08.190
So watch out for that hot reload.

04:08.190 --> 04:10.560
It's still not great.

04:11.070 --> 04:15.940
I was hoping it would be improved in dotnet nine, but it seems we're still in the same position as

04:15.940 --> 04:20.260
when they first enabled this functionality all the way back in dotnet six.

04:21.190 --> 04:22.870
So fingers crossed.

04:22.900 --> 04:27.520
Maybe dotnet ten, maybe dotnet ten will be able to use hot reload.

04:27.550 --> 04:28.780
There's one more test I want to do.

04:28.810 --> 04:31.630
Actually I just want to remove one more item.

04:31.630 --> 04:33.100
The same item, the same request.

04:33.100 --> 04:38.380
I want to make sure that the item with the product ID of two is removed from the basket itself.

04:38.380 --> 04:42.640
So I'm just going to remove that and get baskets.

04:42.670 --> 04:45.910
Click send and we can see we're left with one item.

04:45.910 --> 04:51.040
And if we check what happens when we try and remove an item from the basket where the product doesn't

04:51.040 --> 04:52.060
exist in the basket.

04:52.060 --> 04:53.980
So I'll just send this request one more time.

04:53.980 --> 05:02.500
Then we get the 400 bad request problem updating basket because we did not save any changes into our

05:02.500 --> 05:03.610
database.

05:04.750 --> 05:07.270
So that's the API side of things set up.

05:07.270 --> 05:13.450
Next we're going to turn our attention back to the client and set this functionality up on the client

05:13.450 --> 05:14.380
side.
