Okay, now that we've got our controller with its endpoints, now it's time to go and test our order
creation and our ability to go and get the orders as well.
Now, if we go and take a look at section 11 in postman, we do have some requests.
We've got one to create an order and one to get orders and get order details.
But we need a basket or make sure we have a basket.
And inside section ten, let's just log in and make sure we've got a fresh cookie stored inside postman
for Bob at Test.com.
And if we take a look at getting the basket, see if we've got a cookie.
Still in postman for this I do.
And I've also got a payment intent ID for this one.
Now, is there going to be any point where we create an order where we do not have the payment intent
ID?
I think not.
In fact, I'm so certain of this that I'm questioning why in the order I made the payment intent ID
optional because there should be no occasion where we create an order without there prior to that,
the payment intent ID being created.
So I'm going to set this to required.
Now this is an entity, and I'm not 100% sure if this is going to require an update to the database
schema.
I've also got a warning in the orders controller.
And the reason for that is that the order is using the payment intent ID, but because it is optional
in the basket and it needs to be optional in the basket, then that's something that we're going to
need to check for higher up to make sure we have this before we do attempt to create the order.
So I'm just going to make an adjustment inside here as well and say or and we'll use not string is null
or empty for the basket dot payment intent ID as well.
So we'll just add that check as a third check before we attempt to create an order.
And that should mean and I need to take out the knots there because we're checking to see if that is
null or empty.
And that should mean that our order controller is now clean.
Now, in order to make sure or check to see if we need to update our database schema, we'll just try
and create a new migration here.
So inside the API tab I'm just going to stop the API.
And I'm just going to say dotnet f migrations and order entity updated and press return.
And I just want to check to see if there's anything that does need to change with our database schema.
Now it tells us that an operation was scaffolded that may result in the loss of data.
And that's possible if we had any orders that did not have the payment intent ID set inside our table.
But we haven't created any orders yet, so we're perfectly okay with ignoring that if we go and check
the migration.
I just want to see if there are any changes that are included with this migration.
And sure, there is.
So we do need to apply this to our database.
So it's just going to alter the column and make our payment intent ID not allowed to be nullable.
So that's fine.
We can just restart our app and that will be applied to our database.
So I'm going to go ahead and do that and execute dotnet watch and apply that updated migration to the
database and to make sure our app starts without any errors as well.
Of course.
Okay, so that's fine.
Now we can go test and I've got a basket with a payment intent ID.
Great.
And if we go and take a look at the create order, then what we have here is the properties that make
up our create order DTO.
We've got our shipping address with its properties and we've got our payment summary with its properties
as well.
And that's what we need to create the order.
Now I'm just going to click send.
Please do feel free to practice running through this with the debugger.
We've done this a few times on this course so I'm not going to demonstrate this again now.
But if you do want to see this request happen more slowly, then please do pause the video and run it
through the debugger if you wish to do so.
To give yourself some practice using that, I'm going to just click send on this occasion, and I have
a bad request and it tells us that the shipping address is missing the postal code.
And inside here You won't face this problem because I live adjusted it inside here we've got our postal
code as underscore postal code.
So I'm just making that small adjustment inside here.
And let's rerun that request.
I'll click send again.
And this time we get the 201 created.
And if we take a look and see that we have our order not shaped quite how I'd like it, but it doesn't
look like we've got the object cycle detected error because we can only see one round of this if I just
double check the API as well.
Make sure there's no errors after that request, that looks fine as well.
It's not shaped quite how I want it, so we will do some shaping soon.
But we do have our order being created.
We can see the ID is one.
We've got the buyer email.
The shipping address is what we sent up anyway.
We've got our order date.
We've got the order items.
We have our subtotal.
We have our delivery fee, which is set to zero because the order is $900 in this case.
And we've got our payment intent ID, etc. and the order status is coming back as zero.
Now that's the first item in our order status enum, but I'd prefer that to specify as pending rather
than just a number there.
That's the default.
How this gets returned to us.
And then we've got the payment summary as well.
And if I take a look at getting the orders then click send.
We should get the order back.
And we do.
And if we get the order details well we've only got one order but it's orders forward slash one.
I'll click send on this.
And we've got our order being returned.
Marvellous.
But like I mentioned I don't particularly like the shape of the data.
We've got an issue here with the order items in the details and in not in the list.
That's interesting.
So we've got something to look at with the order details.
There's something different there.
We're obviously not getting the item or the order back with the items.
And I'd like to shape the data a bit more client side friendly as well.
So when it comes to using this, it just makes it easier for us to update the user interface.
And we'll take a look at shaping this order data next.