This video is available to students only

Making Clear Basket Endpoint

In this lesson, we're going to make clear basket endpoint

Making clear basket endpoint#

After the payment is successful, we want to remove the basket from redux as well as from the database. With that, we also want to add courses to users account. Let's start by going to Basket entity and making a ClearBasket method. Since we're going to use it from our controllers, let's make it public. Inside the method, let's make PaymentIntentId to be null, ClientSecret to be null, and we will clear all the items; we can use Items.Clear.

Entity/Basket.cs

Let's go to the BasketController, and here, let's create a new HttpDelete with endpoint being clear. We are not returning anything from this method, so let's just write Task action result, and let's call this endpoint RemoveBasket. We can start by creating a new variable basket which will be equal to await ExtractBasket and we can pass the GetClientId method. Now if basket is null, we will return NotFound. After this, we will use basket dot clear basket. Now we can simply copy this logic from RemoveBasketItem and paste here. Just change "Problem clearing the basket".

Start a new discussion. All notification go to the author.