In this video.
Let's go ahead and finish up the MVC design pattern to have clean folder structure.
So looking at the route here at this point, I think everything is okay because we have what is called
separation of concern.
But to be able to finish up with the MVC design part in the purpose for the routing is to take a function
and then just render that.
So we need to catch the logic inside this route.
So for this route, where is our business logic?
This is the entire route.
The business logic lies inside the callback, which is this one.
So we need to catch this one and put it on a separate file called controller.
The responsibility of a controller is where we implement the business logic.
So let's go ahead and then refactor the code inside the root so inside the controllers.
And let's start with the users and let me create one file and our code is one as users dot JS And let's
come back to the root.
So let me get back to the users root here and this is a callback function, so I'm going to cut the
callback function inside here as that and come back to the controller and I'll paste it as that.
This is a valid function and this is what we call anonymous function, meaning a function without a
name.
So what we need to do is to assign a variable to this, or we can make use of normal function creation.
But I would like to use a function.
So this one going to be as a registered user controller or registered controller equal to that, and
that is it.
The next step is that I need to require that one inside the root.
So I need to export down here as module dot exports is equal to remember this file is going to contain
all the logic about the users, meaning we are going to export multiple functions from this file.
So we need to export them as an object as register controller.
So in here I need to require the registered user controller and our pass to this one as a second element
and that is it.
So when I go ahead and then make a request to register, you can see that it worked fine.
So let's finish up the refactoring.
So back here I'm going to cut all the callback function and inside here I'm going to paste it here.
So it's not going to be as log in.
And this one is registered.
It's supposed to be here before the export.
So I need to assign to a variable called log in const log in controller is equal to that.
All right, so let me collapse the finished one and let me export us log in controller.
And here, let's require it as log in.
Sorry as log in and here as log in.
The next one is for the getting details about the user.
So here I'm going to be as details so PC eight.
And I signed to a variable called user details.
Controller is equal to that.
So let's export it as that and here require it as that.
And for details, I'll start next one going to be the profile.
So let me select and cut and here, let me collapse this one also.
And this one is going to be the profile piece, its end cost profile controller.
Is equal to that exports.
Required.
And use it.
Next is.
Upload profile photo.
So select and cut.
Going to be upload profile photo.
Pace eight.
In concert upload profile.
Photo controller.
Wow.
It's too long, but it's okay.
So down here.
Less exports and less required.
And here, let's use it.
The next age upload cover, photo it from here and let me collapse here as upload cover image and then
cost.
Upload cover image.
Controller is equal to the function code.
And exports.
And here.
Let's use it.
The next one is I need to use it here.
And the next one is update password.
So here is going to be update password and const.
Our date password.
Controller is equal to that.
And let's use it here as update.
Next one is going to be the update the user.
So let's come back here and want to be an update user and I'm going to be const update user is equal
to the function.
Going to be controller.
So let's export it here and let's use it here.
And let's use it also here.
The last one is going to be look out.
Cost.
Look out.
Controller is equal to that.
Let me collapse.
It's.
Look out.
And here I look out and let's use it here.
All right, So let's try it out and make the request to make sure that it works fine.
All right.
So let's work with the post controller also.
So let me collapse this one.
And inside the post I'm going to create one file and call it as post.
Jeez.
Let's get back to the post route.
Which is this?
And as we did.
Cut it from here and post const create post controller is equal to the function call.
So here are going to be as great.
And down here exports module dot exports is equal to create post controller collapse AIDS.
And next step is.
Fetching all posts.
So here is going to be all and cost.
Fetch post.
Post prowler.
Is equal to the function call and let's export us an object to here.
Can it be as fetch post?
And for single.
Cut it from here.
And details the contest fetch posts.
Single post controller is equal to that.
Let me add controller for the function on.
All right.
The next A's delete.
Delete content.
Delete posts.
Controller
is equal to that.
And lastly is about the update.
And let's export it here.
As update.
So let's require out the controllers create.
So here are going to be as great.
Delete.
Fetch.
Single update.
So this one is for fetch.
Post and fetch single post.
And delete posts and update posts.
So let's test it out and see if it works.
So great is fine or also fine details is also fine.
Have to rename this one to details.
Well, spelling mistake and delete is fine.
Updates is also fine.
The last step is for the comment.
So let me collapse all and insert here.
I'm going to create a file called Comments dot touches and inside the root of comment.
Let's start with that.
So let me cut this one from here.
And inside here is going to be a great comment.
Second, great
comment.
Controller is equal to that.
And then.
Fine single comment.
Cost comment details controller is equal to that.
And next is the lead.
Konst deletes comments.
Controller.
Is equal to that.
And lastly is for update.
Costs.
Update.
Comments.
Controller is equal to that.
So let's export the module.
You're going to be as great.
Comment details.
Delete.
Update.
And that is it for now.
So let's come here and then require great comment.
Comment, details, delete and update.
So here is going to be great comment and this is comment details and this is the lead comment and this
one is update comment.
So now we have complete MVC design pattern.
What has left is to fill up the actual logic for our application.
Then this video, let's start with user registration.