Hello and welcome back.
Now that we have the methods to get data from you, follow us cash or the follow up collection.
Let's go ahead and add the controller.
So this is going to be called let's follow us, let's see us.
So it's just going to consist of a class and two methods.
So let me just go ahead and.
Get what I want.
I think I need this.
Right here.
And also, I need the.
A mongoose
imports.
And practical need to follow our cash as well.
Let me get inputs here.
So now let me create the class or exports class.
I'll call this gets and the method public async.
I'll call this user following
request and then the second property will be response of type response, promise of type void OC.
So what we are going to do here is first I'll construct a property of type object ID if we go to our
shared services.
DB If you remember, that's the property that we need to pass in most of type object ID and that is
going to be the ID of the currently logged in user.
So for the user, following the currently logged in user, if they want to get all the users that they
are following, we are going to use this.
So course I'll see user objects, ID of type objects ID equal to new mongoose dot types, not object
ID and then our passing request the current user not user ID.
Now we need to get first of all, check the cache just like how we've been doing so.
I'll say cached.
Follow us.
It's going to be of type.
I follow a data list equal to a weight for cash.
Dot gets follow us from cash.
And now here we need to pass in the key.
We need to pass the key.
And for this, the key is going to be.
We want to get the following.
So it's going to be something like this.
The top level key, which is full in this case, the top level key which is following colon, then the
ID that we want to pass.
So if we want to get all the following for this particular user, we pass following Colon and the user
ID.
So it's going to be following Colon.
Now, in this case, it's going to be.
This.
Requests current user Dot's user ID, so I think I need to import this.
I think I can just get it from here.
Okay.
And then we can perform our check.
So costs.
Following of type.
Now we have a type for this squad.
I follow
or I follow data equal to so we check if cached follow us not length.
So if it actually returns data then we use the cached follow us so it will use the return result.
No need of going to the database, but if no data then we go to the database and now this is going to
be follow follower service.
I need to import this.
But gets full of data and then we pass the user.
Object?
I do.
I think I need to import this as well.
Now for some reason doesn't just respond quickly.
So let's see.
Yes.
In fact, we don't even need it.
We don't need it because we already transformed the results.
We are not returning the results in this form.
Instead, we are returning leads in in this form.
That is what we did with this right here.
So we don't need that.
I follow.
Oh, I follow all this.
We don't need it.
So this is what we've done.
What we just need to do is.
Whole rest of status.
And here is going to be a message user following.
And then the data we want to send is going to be have a key of following and the value of following.
So this is what we are sending.
The key is called following and the values, the results in this following.
But we use the shorthand right here.
So this is just all we need.
This is what we need in order for us to be able to to get the user following data.
Now, I would duplicate this and just make the necessary changes.
This is going to be called user.
Follow us.
We put this time we're not getting from request current user.
We are going to get requests dot params, not current user.
So this is going to be dot params.
But now here is going to be follow us.
And then this data is going to be follow up.
We already have all this.
And yeah, I can change this to
follow us
right here.
Oh, I can.
Let me change this to cash for Luis.
Okay.
And here these are followers.
So these are the methods that we have created.
Let's go ahead and create the roots.
So go to roots.
Follow our roots.
So what this is going to be to get roots.
So it's going to be get.
So the first one is just going to be user slash following and this is going to be gets.
And I want to get it from.
Follow us.
Right here.
And it's going to be called user following.
And then the next one is going to be.
Use our followers
and for the second get roots, it's going to be user slash followers.
Slash user ID.
I think that's what we are using here.
Slash user ID.
So these are the two HTTP methods we're using to get.
For users large following and get also user slots follow slash user ID.
So now we have both.
Let's go ahead and test them out.
Let's see.
So I to follow.
So for the first one, it's going to be.
Let me make sure that I'm logged in.
So this is still reloading, so I'll sign out.
Signing again.
Okay.
So now I'll change this to Cats and Roots.
Is this.
So let me copy this.
Okay.
Now you can see this user is following two other users.
So they log, the user is following two other users.
So you can see we have two objects right here.
This is the first one and this is the second one.
And you can see the object fields and values.
We have the user name, the avatar colour, we have the UID right here and we can also do the second.
So.
So for the second I want to get the followers for a specific user.
So let's say for example this user.
This is a has one for last count.
So let me get the ID.
Right here.
And let me do the same.
And you can see I have just only one object.
One results, which says Follow us.
So right now, this data are coming from the cache.
Let's try it out for.
The database.
So what I'm going to do is simple.
Let me just remove this.
You can remove these and then do the same here.
I will do this later and see.
So let me go ahead and try it out.
We'll see for this.
And now you can see we still get the same results.
This data is coming from the database and not the cache, while this other one as well is coming from
the database.
So if I try to get for this, so let me get the full loss for this user.
I expect this to be empty.
So.
Yes, this is empty because there's no other user is following this user with this ID.
So that's why you see we get an empty user list.
So right now our feature is working.
We can follow a user and follow user.
We can also get the data from the cache or from the database.
So go ahead and do this.