In this video.
Let's get started by creating the root and controllers for our application.
First step is that we are going to work with the users.
After that, we will go ahead and work with the post API and then the comments API by the design pattern
that we are going to use is called MVC design pattern.
But before we get into that, I would like guys to move slowly.
In that way.
You better understand how the MVC design pattern works.
So first step is we are going to write all the code on one file, then you go ahead and refactor using
express routing and lastly to use MVC design pattern.
So for the root, we're going to have this root first one going to be the user's root and next step
going to be the post root and it's going to be the common root.
All right.
So let me remove this one and let me add beautiful command to the user's root.
Likewise the post route.
We are going to fill them up as we move on.
And he is going to be the comments.
All right.
So let's start with the users.
The first one is going to be post request going to be API for slash version one for slash users and
for its last register going to be the register endpoint.
So going to be app dot post, then pass in the endpoint that is the API and then the register next I'm
going to be the callback.
I have access to request response and as that and we are going to use async for this.
So inside here I'm going to make use of try and catch.
And for the meantime, let's send this JSON data because we are developing the API.
That's why we are going to send JSON data either because or API, we need to send back JSON data format.
So I provide the starters for this one and I will say success and I will need this one in the front
end.
As we move on, you better understand these properties.
Next, I'm going to be the user and I'll provide as user registered.
I start in case something goes wrong.
Let's send rest, Jason, and we're going to sign the entire error.
And we have a section where we are going to add our custom error handlers.
All right, So now we have the first one for register.
I can copy this one and let me collapse this one and I'll paste down here and change this one to log
in and I'll change this one to log in also.
And when I be as user, log in.
So the same post method I could logs it.
The next one is going to be the details about the user.
So here is going to be as get an API, I'll provide dynamic ID, I'll start and here provide the dynamic
ID and we are going to use this endpoint to find details about a user.
So here as a single user or user details.
And collapse it.
And I'll copy this one.
And down here I'll paste this one and change this one to profile.
And then four slash ID and you're going to be asked to file for a slash ID.
So these two endpoint single and profile, the first one is going to be the public, meaning that if
a user is viewing a post, that person can view the creator of the post, but for the profile is going
to be private, meaning when it belong to the creator only.
So here when I get requests like y this US gets requests.
So after that we are going to create one end point for uploading profile image.
So here is going to be as put request because we are updating a user property.
Right?
So here need to provide users and I'll provide a profile upload.
And here you need to provide the ID of the user.
But as you move on, we will do away with the ID, but instead we will get the user ID from the root.
For the meantime, let's maintain this.
So let me rename this one as pull five photo upload to be more specific.
So I'm going to copy this one and I'll paste it here.
Sorry.
It's supposed to be forward slash and then forward slash like that and like that.
So next one is going to be uploading the cover image.
So this one going to be put in here also as put.
And he's going to be as cover photo upload.
All right.
So let me change the text here as user profile image upload.
And for the cover, I'm going to be as user cover image upload.
Right.
The next one is going to be the updating the user password.
So I'll copy this one.
And down here, I would change this one to users and update password.
And let me provide the same name here.
As that.
Going to be as use a password update.
All right.
The next one going to be the lockout.
So.
This one going to be Gates request.
So here is going to be get an API users and then look out.
As that.
So I would change this one to look out.
And then use that look out.
Perfect.
So here is going to be get so this other route that you may need for now in case we left some behind.
Definitely.
We will come back and then fix it.
So now we are done with the user.
So what about the post?
So let's copy one of this ones and let's come back to post route and let's paste this one and change
this one to post and here provide us post.
And inside here it's going to be as post created.
And let me collapse.
So let me change this one to post.
Let me copy this one down here, piece eight and change this one to fetch all So we're going to be get.
And then post.
So a difference here is going to be the HTTP method gets I'm going to be as post list.
So let me collapse X and copy.
And here I'm going to paste.
Going to be a single voice slash colon ID and forced slash colon ID and going to be post details.
Let me collapse it and copy this one and this one is going to be delete.
Post and difference here is going to be the HTTP method as delete and post deleted.
So let me collapse it and copy this one down here.
Going to be updates.
It's going to be as put.
So here difference here is the HTTP method called puts and here as posts update it.
All right.
So now we have that one.
Let's copy all this one for the post and let's paste here and our comments.
All right.
So let's start here.
That is the comment here for creating it going to be as comments and select this one and press command
D for multiple selection.
I would change this one to comment and here as comments created.
For this one.
You don't need it to fetch or comment.
So I remove that.
I want to find a single comment, for example, if I want to update so I will need this one.
I would change this one to comment and here as comments details.
Right.
Next one going to be the delete.
So we are going to be as comments and here as comments deleted.
And I can also update.
So I would change this one to.
Comments.
Voice ID and the same as put in here as comment.
All right.
So these are the routes we need for our application.
The next video.
Let's go ahead and test the endpoint using the ten dot client extension.