Hey there, everyone here.
And welcome to another video.
In this video, we're going to design a product model.
Now, the product model can be called with variety of names.
You can call it as t shirt model, you can call it as a course model in case you are designing an education,
LMS or something.
You can also call your A product as simply the order or the food item somebody is placing or a pizza,
whatever you like to call it.
There can be many names and there is ridiculous amount of similarities in the product itself.
Now another important thing is each of these products are also going to have a reviews.
Now, if this would be something like my school or something, I would love to create a different table
itself for the reviews itself.
But since we are talking about the NoSQL database, one of the advantages we can just inject all things
up here, and even though it is a little bit sounds complex, but it is not, this is how exactly the
NoSQL is being designed for.
So let's go ahead and create another model and we are going to call this one as simply product.
Now, this product, again, as I told you, it can be anything at all.
So what we're going to do again, same kind of a sticky note.
Let's go ahead and pick up with a different color.
Let's go with a green.
Yep.
That sounds good.
Okay.
So let me bring it up here a little bit.
Looks great.
Now what?
We're going to go ahead and call this one.
So, again, a product is always going to have a name and a price.
This is pretty obvious and a description as well.
So description.
So these are common things.
We all know that the product is going to have a name, price and description.
What all what else is going to have?
It's going to have an image as well.
Let's just call it as photo, keep the things as same.
So this is going to be photo, but this is not going to be photo.
This is going to be photos because a product can have multiple photos in this case.
So we're going to be keeping it as an array.
What we're going to inject in this setting.
Yes, you guessed it right.
Just like previously, we are going to inject an an object which will contain an ID and a security model.
So we'll be injecting as many as we like into this array.
So pretty simple.
No big deal there.
It will also have a category.
Now, since we don't have too much of the things to be worried about, the categories there are only
just for.
That's why we are going to be calling an E nums, which will help us to explore the enum a little bit
better as well.
But don't worry, we will learn how to inject different model into other models as well.
So in case for the future, you want to have a separate model for the categories itself.
It's ridiculously simple.
So you can actually you will be able to do it.
Don't you worry on that.
Okay.
Once we are done with the categories and all of that, we will also inject a brand.
Now why brand?
Right now we are selling all the t shirts with the name of AE.
Maybe later on we want to sell t shirts from Adidas or Nike or something else, so we'll be keeping
it up here.
It will be a simple string.
You want to have it, keep it if you don't want to have it, no big issue, we can actually move that.
So this is how usually the brand and integrity of the product is designed.
You just brainstorm which which feels you want to have, which feels you don't want to have, and that's
how things are being designed.
Okay, so once we have this one, obviously the one of the requirement was to have a stock.
Now stock is going to be a simple number and we are going to manage this number on our own.
We will design the controllers in such a way that whenever a order is being placed, we'll find out
how many quantities of that product is being ordered and we'll subtract it from the stock itself.
So this is going to be managed by our self and it will be automatically managed.
The user will not be worried on that.
Now every single of the product is going to have a ratings as well.
Now this ratings field is going to be taking care of what is the average rating of the product.
So we need to calculate that as well.
As soon as somebody adds a review, we'll take his rating and we'll kind of adjust in this rating field
here.
So this is going to be interesting to work on that, how we figured out the ratings part as well.
Now, it will be helpful for us if we go ahead and say a number of reviews now why we want to have a
number of reviews.
There will be obviously a field in the website itself which says total number of reviews.
But not only that, it will also help us to design decide the ratings, which we just wrote above,
how the number, the total rating is going to be, that whatever the ratings are divided by the number
of reviews we have.
So calculating the average, this field is going to help us at that point also.
So a number of reviews, again, it's not going to be too much important, but I think this is an important
part.
Further down the road, we will have the reviews.
Now, what this reviews is going to be, this is going to be in array again.
Now, what we're going to fill up into this reviews.
So what I will do, I will add a user itself.
So obviously the user model that we have created, we need to inject that so that we can find out who
is the user who has added the rating.
We will take his name also.
We can add his email, but I don't think so.
That's too much necessary.
And we are going to go ahead and collect rating from him and we are going to collect comment on him.
You can call this rating as star as well, but I think rating is itself kind of a decent name for that.
So that's that's okay.
Let me expand this a little bit.
So so far so good.
Now we have a number of we have the ratings average one.
We have number of ratings, total number of reviews given to this product.
We have reviews, which is an array in which user needs to add, enter its rating and comment and we
will automatically collect who is the user who is entering the rating.
So we need to take care about user should be logged in and the name of the user.
So no big deal.
Just kind of a basic.
Now another thing that we are going to inject here is the user itself.
So whoever is the user who is adding this product, we need to take care of that because right now you
are just having one admin, but maybe you want to give this feature to some kind of manager as well
in the future.
So to make it this a little bit future proof, we are going to add this user into the database itself
that, hey, this is this was the guy who actually added this product on to your website.
So pretty okay, pretty good.
And of course, every single of them is going to have a field which is going to be created out.
So no big deal there.
Is this the only thing that we are going to worry about?
No, probably we can add a few more fields can work out with that.
But this is kind of a brainstorming session that I'm having just with you.
So we're going to be keeping this as simple as short.
In case you come up with any more field, you can go ahead and definitely add them once you are done
with the course.
So this is all the basics of product.
Now, again, this kind of discussion actually evolves a little bit more when you are selling the courses
or maybe you are selling some restaurants or the pizza because their fields are going to be different
from what I have used up here.
And in fact, even in the t shirt store, there can be more fields or something more that we can have,
but we're going to keep it short.
Let's keep it up here.
And in the next video, let's talk about how the order model is going to work on when somebody plays
order to our website, how that field is going to look like.
Let's catch up for the next video.