aboutsummaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
Diffstat (limited to 'Backend')
-rw-r--r--Backend/Api/Api/Controllers/UserController.cs7
-rw-r--r--Backend/Api/Api/Interfaces/IUserService.cs2
-rw-r--r--Backend/Api/Api/Services/UserService.cs43
3 files changed, 52 insertions, 0 deletions
diff --git a/Backend/Api/Api/Controllers/UserController.cs b/Backend/Api/Api/Controllers/UserController.cs
index cc45737..4d7905a 100644
--- a/Backend/Api/Api/Controllers/UserController.cs
+++ b/Backend/Api/Api/Controllers/UserController.cs
@@ -116,5 +116,12 @@ namespace Api.Controllers
{
return Ok(await _userService.Unfollow(id));
}
+
+ [HttpGet("{id}/myFollowers")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<UserSend>>> GetMyFollowers()
+ {
+ return Ok(await _userService.GetMyFollowers());
+ }
}
}
diff --git a/Backend/Api/Api/Interfaces/IUserService.cs b/Backend/Api/Api/Interfaces/IUserService.cs
index 5f99733..95dd46d 100644
--- a/Backend/Api/Api/Interfaces/IUserService.cs
+++ b/Backend/Api/Api/Interfaces/IUserService.cs
@@ -35,5 +35,7 @@ namespace Api.Interfaces
Task<Boolean> CheckIfAlreadyFollow(string id);
Task<Boolean> Unfollow(string id);
+ Task<List<UserSend>> GetMyFollowers();
+
}
}
diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs
index d95b5eb..ec67729 100644
--- a/Backend/Api/Api/Services/UserService.cs
+++ b/Backend/Api/Api/Services/UserService.cs
@@ -535,9 +535,12 @@ namespace Api.Services
continue;
}
UserSend following = new UserSend();
+ following.creationDate = utemp.creationDate;
+ following.name = utemp.name;
following.pfp = utemp.pfp;
following.username = utemp.username;
following.email = utemp.username;
+ following.following = utemp.following;
following.followers = utemp.followers;
following._id = utemp._id;
@@ -621,5 +624,45 @@ namespace Api.Services
}
return false;
}
+
+ public async Task<List<UserSend>> GetMyFollowers()
+ {
+
+ string id = null;
+
+ if (_httpContext.HttpContext.User.FindFirstValue("id") != null)
+ {
+ id = _httpContext.HttpContext.User.FindFirstValue("id").ToString();
+ }
+ User u = await _users.Find(user => user._id == id).FirstOrDefaultAsync();
+ List<UserSend> myfollowers = new List<UserSend>();
+
+ if (u!=null && u.followers != null && u.followers.Count() > 0)
+ {
+ foreach (string userid in u.followers)
+ {
+ User utemp = await _users.Find(user => user._id == userid).FirstOrDefaultAsync();
+ if (utemp == null)
+ {
+ continue;
+ }
+ UserSend follower = new UserSend();
+ follower.creationDate = utemp.creationDate;
+ follower.name = utemp.name;
+ follower.pfp = utemp.pfp;
+ follower.username = utemp.username;
+ follower.email = utemp.username;
+ follower.following = utemp.following;
+ follower.followers = utemp.followers;
+ follower._id = utemp._id;
+
+ myfollowers.Add((UserSend)follower);
+ }
+ return myfollowers;
+ }
+
+ return null;
}
+ }
+
}