Hey there, welcome back friends. In this video we will try to understand how to perform the Delete operation. And in fact this operation is very simple. And this is also similar to the update post operation. So first of all let us copy this particular part. And we will paste this in here.
And we will make some changes. All right, first of all let us update the name of this method. And now, we will give the name as delete post. All right. And the method would be this time not put, but delete. All right, everything other than this is good enough.
Now in here we don't need an object. We simply need the ID so we won't need this parameter. All right, and now moving forward, let us create method in our service layer, which will indeed delete the specific element from that list. So the name would be, for example, delete, post, and we'll pass on ID. And that's it. Alright, so now moving forward, let us navigate to our service layer by creating the method delete post.
So here is our service layer. Now again, the functionality though we're a logic inside this delete post would be similar to the update post, we will simply copy the business logic from this particular method and we will paste this in here. All right, and in here, we will simply remove this particular line from line number 51. And in place of line number 51. Now, the logic will change a little. In here we will type in posts dot remove and we will pass on the index and index Definitely I never work is done.
So this is very simple easy to understand easy to implement, we are simply iterating we are simply searching the specific element which we want to delete. And if we find the element in our list, we will delete the element and we will return the controller. Now, the overall logic is definitely similar to the update post. Alright, so, our delete operation is done, which is very simple to implement. Now, finally, let us try to run this application. And let us try to check whether our application is working properly or not.
Alright, so our application is up and running. Let us navigate to Google Chrome. Let me open our extension. And first of all, let me show you the list of posts. Here we go. Let me delete the element with ID five.
So in here, first of all, we will navigate to the URL where the ID is five here is what we say element. And now, in place of get method, we will make use of the Delete method. And we will send the request. All right. And now, if I list on all the posts, here we go. So there is no element with ID five.
And if I try to extract the information with ID five, there is nothing. Likewise, we can also delete some other entity, for example, deleting the element with ID two. Let me show you. Again, the operation was successful. And here is the output. There are only three elements now with ID one, three and four.
Perfect so everything is good enough nice. And this is it. Now friends moving forward from our next video, we will start exploring how we can communicate with the database and perform similar operation by connecting with the database and performing the CRUD operations directly. On the database. All right, so something interesting is coming up. I hope you guys enjoyed this video.
Thanks for watching. Have a nice day and take care