Okay, hopefully you gave this a go to populate the code we need in the remove basket item.
I'll just run through what the approach to this is.
Anyway, it's a fairly quick method that we need to create here because we've got most of the code.
We need all the reusable code we kind of need anyway, certainly in regards to the getting of the basket.
So I'll specify var basket equals await and retrieve basket.
That's the first step.
And then we need to remove the item or reduce its quantity.
And again this is something that we've already created in our basket entity.
But before we get to that we need to make sure the basket is not equal to null.
So I'm going to check to see if the basket is equal to null.
And if it is, I'm going to return a bad request and say unable to retrieve baskets as we cannot remove
an item from a basket if we do not have that basket, the next step is to actually remove the item.
And because we already created this helper method in our entity, it's just a matter of using basket
remove item and then in the remove item.
If you're wondering what properties you need to send for a specific method because you created it some
time ago, it's got many different arguments that you need to pass.
Then just open up some new parentheses and then press escape.
And then this will give you the documentation about what arguments this method accepts.
So we need a product ID and we need a quantity.
And when we've got our arguments in parentheses like this ordering is important.
We need the product ID to be first and we need the quantity ID second.
So in this case we'll specify the product ID and then the quantity.
And then we can save changes.
So I'm just going to copy the code I have here the var results and save those changes.
And then we can check the results and say if Results.
Is effectively true.
Then we're going to return okay.
Which is the correct response to send back for an HTTP delete method if it was successful.
Otherwise, we're going to return a bad request and say problem updating baskets.
So great.
That is now our remove method.
And if I just open up the terminal and it says file updated, I'm going to see if Hot Reload has worked
for this one.
So let's go back to postman and I'll click on the remove the item from the basket.
So product ID of two quantity of one.
If I take a look at what I currently have for the basket and click send and where's my response gone.
It's hidden down here.
So I've currently got a quantity of two for the product ID of two.
I'd expect that to go down to one.
So if I click on this request and click send I get the 200.
Okay.
There's no more details in this.
That's what we'd expect.
So I'm going to need to get the basket again to make sure that it has been updated.
I'll click send and something did not work because that quantity is still two.
And yeah, it's still two.
And what went wrong?
There is my question.
So let's head back to VS code.
I did say that was relatively simple, but what I didn't do, and this is no doubt the problem.
The first troubleshooting step always, always restart the API server.
I thought I'd see if hot reload would accommodate that change.
It doesn't look like it has or it could be the reason.
So I'm just going to restart the API server and see if that does fix the problem.
So I'll go back to postman.
I'll click send again for the remove item from basket and we get the 200.
Okay.
Again, if I go and get the basket I'd like to see that quantity reduced to one.
I'll click send and sure enough it has indeed gone down to one.
So watch out for that hot reload.
It's still not great.
I was hoping it would be improved in dotnet nine, but it seems we're still in the same position as
when they first enabled this functionality all the way back in dotnet six.
So fingers crossed.
Maybe dotnet ten, maybe dotnet ten will be able to use hot reload.
There's one more test I want to do.
Actually I just want to remove one more item.
The same item, the same request.
I want to make sure that the item with the product ID of two is removed from the basket itself.
So I'm just going to remove that and get baskets.
Click send and we can see we're left with one item.
And if we check what happens when we try and remove an item from the basket where the product doesn't
exist in the basket.
So I'll just send this request one more time.
Then we get the 400 bad request problem updating basket because we did not save any changes into our
database.
So that's the API side of things set up.
Next we're going to turn our attention back to the client and set this functionality up on the client
side.