diff options
author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-12-08 13:45:26 +0100 |
---|---|---|
committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-12-08 13:45:26 +0100 |
commit | d0f30cf2d8fcd745234b45a3cb450de812da7c61 (patch) | |
tree | c48e84adbce59775f90b04ef3064123177629ede /Backend/Api | |
parent | 97d62835b3e52395022d3f5920ddb1658b9c4c18 (diff) |
Follow/Unfollow ispravljen.
Diffstat (limited to 'Backend/Api')
-rw-r--r-- | Backend/Api/Api/Services/UserService.cs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs index 2b3f0b8..98938c0 100644 --- a/Backend/Api/Api/Services/UserService.cs +++ b/Backend/Api/Api/Services/UserService.cs @@ -416,7 +416,9 @@ namespace Api.Services } User f = await _users.Find(user => user._id == followerId).FirstOrDefaultAsync(); User u = await _users.Find(user => user._id == id).FirstOrDefaultAsync(); - + if(await CheckIfAlreadyFollow(followerId)) + return false; + if (id != null && followerId!=null) { if (f.followers == null) @@ -617,27 +619,33 @@ namespace Api.Services User u = await _users.Find(user => user._id == myId).FirstOrDefaultAsync(); User f = await _users.Find(user => user._id == id).FirstOrDefaultAsync(); - + if(await CheckIfAlreadyFollow(id)) if (u != null) { - if (u.following != null && f.followers!=null) - { u.following.Remove(f._id); + if (u.following == null) + u.following = new List<string>(); u.followingCount=u.following.Count(); + if (u.followers == null) + u.followers = new List<string>(); u.followersCount = u.followers.Count(); f.followers.Remove(u._id); + if (f.followers == null) + f.followers = new List<string>(); f.followersCount =f.followers.Count(); + if (f.following == null) + f.following = new List<string>(); f.followingCount =f.following.Count(); - _users.ReplaceOne(user => user._id == myId, u); - _users.ReplaceOne(user => user._id == id, f); + await _users.ReplaceOneAsync(user => user._id == myId, u); + await _users.ReplaceOneAsync(user => user._id == id, f); //updateUserFollowerFollowingCount(u.followers, u.following, u._id); //updateUserFollowerFollowingCount(f.followers, f.following, f._id); return true; - } + } return false; |