Hey, did everyone that they share and welcome to another section.
So the previous section, we had a lot of discussion about the user model, which is a pretty common
model in every application that you will be building up.
Now, in this section, we're going to talk about another very common model, which is a product model.
Now, before I talk about the product model, here is something that I've created, as I discussed earlier
with you in the section that I won't be showing you that.
How am I actually writing this?
Because this is really basics.
We have already in the chapter two scene that how we can write the documentation.
And also apart from this, this entire swagger documentation will be available to you.
So in case you want to check it out, you can always go ahead and look into this.
That's how this was written and everything.
Discussion part.
We have already done it and whenever I'm getting some free time in between editing the videos and all
of that, that's where I'm writing this.
So just showing you that, yes, I've categorized this into home users, admin and manager and we'll
have a lot more features now.
Just specific to products, some more categories will go into admin and whole bunch of stuff.
So for example, in the post category, we designed a simple URL or a root which say slash admin, slash
user and if it provides an ID, he can edit the ID of the URL.
So these are the fields that he can manipulate.
I have restricted the user from a user admin and manager.
These are the role he can actually apply and all these fields are necessary.
The ID will go in the path, rest will go into the farm data or the body itself.
So really very basic.
Something that we have already seen.
Nothing groundbreaking or nothing magical.
In case you want to see, you can check this out.
Moving on.
So what we're going to do now in the previous one, the previous all section, in fact, a couple of
sections we have talked about in depth about user model.
And that's all you'll be doing is whatever the application here, you will be building up JWT tokens
and password resets and forgot password, maybe verification of the user or something similar.
So that part is all covered up and I'm pretty sure any more functionality that comes to your way, you'll
be absolutely able to mail it down.
Now moving on to the another big major part when you'll be developing any application is the product
itself now, although I call it as the product here, but I in personal life call this one as a card
feature or a card model.
Now, why do I say it as a card?
Because whatever the application you are going to be building up, this is the major card that comes
into the picture.
For example, in case you are working with any shopping application, then all the products actually
come into that card.
So all the pricing details, all the kind of a name of the product photos, everything comes there.
If you order food, that food itself is a card item.
So your pizza, whatever you're ordering up, this is all entirely going up there in every application
you need to figure out what is the product itself.
That is the main thing that you are selling for me at my online website.
The courses are the product itself, so they are the card items.
So that is what I mean to say about that.
Now in these ones, just like in the previous one, we saw that these are the things going on with the
token middleware side of the cache cases of handling images, reset password and all of that.
These are the major features that we work with the user model.
In the case of product model, the major that we work on is the refs.
For example, you want to inject some another model into this product model.
For example, we'll be injecting user whoever is going to create the model.
So we are going to learn that how we can interact with the model.
This model needs to interact with another model, so we need to have a relation between them.
So how we can do that, that's going to be the one thing.
Another thing that we work on with is the pagination, the search thing or the filter.
So I'll walk you through that.
How you can actually use these search things.
You can use some of the pagination filters, kind of a very common, absolute common thing in the product.
And that's going to be our major journey of understanding throughout this section.
It is really easy compared to the previous one.
What we have seen, it's rather very easy.
Okay, so let's go ahead and do a setup.
I won't be talking much on to the YAML here, so let's go ahead and close all of this.
Okay.
Now, interestingly, we need to have another model, so let's go ahead and create a new file.
We are going to call this one as simply product JS because this model will handle the entirety of the
product.
Now similar to this, we have to create a controller, so let's go ahead and create a new file into
this one.
So this one is going to be simply product.
Product Controller Controller GS.
And here all of the roots will come up.
So whatever the roots we had previously, like we had some roots in the home and stuff.
So we're going to be using something like that.
In fact, what I can do is I can actually copy this and I will put it into product controller.
So let's go ahead and put that.
And this one is going to be just for momentarily as a test product so that we can see everything is
working fine or not.
This tri catch.
Yeah, seems okay.
Nothing too bad.
But actually we don't need this watch, so we're going to go ahead and remove this one.
We don't need any catch functionality.
We just need somebody to say, hey, this is this is a test for product.
So let's go ahead and say this is a test for.
Product save that looks okay.
Now, the next thing that we do is we need to have some roots as well.
So this is going to be the root for product call.
This one is product root or simply product JS however you like, and this is going to have exact same
functionality as for the user.
We have discussed quite a lot about this one in the past, so we're going to go ahead and borrow some
code from here.
So let's go ahead and copy this.
And inside the product root, let's go ahead and paste that.
Now at the very end of it, we need to export this router, so let's go ahead and copy this and export
this one and told you once we set up the things, the next of the things after that remains really,
really easy.
So this is all what we got and this is how we are going to be working on.
We need to import our test product root here as well.
So let's go ahead and add that since we are going to need middleware as well, let's copy this and bring
in the middleware as well.
And after that, we're going to need the test product.
So we're going to say, hey, test product, let's bring that.
So test product is here and now we need to create a simple root.
So let me remove this and let's copy another line and this line looks okay.
Just grab any line or in case you want to write that, that's fine too.
And I'm going to go ahead and make this one as simply test product and it will be governed by the test
product controller.
Okay, so this is it, but this is not the entirety of the stuff we need to just once, for once we
have to touch this.
JS Because this root needs to go there as well.
So if I go ahead and check here, I'm importing all of the roots.
So let's go ahead and bring this one.
Let's go ahead and call this one as simply product.
And this will be coming up from Roots slash product.
And let's go ahead and create a middleware for this one as well.
That, hey, on the same one, the roots are going to be controlled by the product itself.
So there we go.
Now, in theory at least, we have set it up in such a way that we are exporting a controller.
There is a model as well.
We haven't worked on that, but there is a controller which is test product which will be governed on
some route that we have mentioned up here.
And we have abg's configured that the middleware actually sends all these routes if it is there into
these files.
So all we've got to do is let's go ahead and change this one to get and see if the test product route
is there or we can actually go ahead and grab it.
So copy that.
Let's go up here.
And obviously I would love to create a new folder here because we'll be testing up new things.
So let's go ahead and say add a folder and I'm going to call this one folder as simply product.
And let's close all of these.
Some of them are good.
Some of them need to be changed a little bit.
Probably I'll check them later on, but I'm not too much worried because I've already worked quite a
lot on the swagger.
So that is it.
Okay.
And come on, please don't show me this.
I just want to close.
And there we go.
Okay, so let's go ahead and now create a request onto this product.
So let's go ahead and say, hey, I want to add a.
At a request of this product.
First, I'm going to go ahead and save this one.
So this one is going to be test product.
I'm not going to keep it.
I'm just showing you how to how to actually go ahead and add that into the t shirt store, go into the
product and go ahead and save this one.
So now this all the requests are going inside that one.
And all we've got to do is simply go ahead and say, hey, domain.
There we go.
My domain, not domain.
And this one is slash test product.
If I go ahead and send a get request, we are getting that this is a test product route.
So everything is working absolutely fine.
As expected, at least our routes and controllers are there.
In the next video, we're going to work on the models and this is where you are going to see that,
how you can inject existing model into this particular model itself.
This will help you to understand that how we can inject users, maybe you want to add some another models
and want to inject them here.
So it's going to be all in control there.
Let's go ahead and catch up in the next video.