diff options
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/Api/Api/Models/User.cs | 4 | ||||
-rw-r--r-- | Backend/Api/Api/Services/PostService.cs | 6 | ||||
-rw-r--r-- | Backend/Api/Api/Services/UserService.cs | 10 |
3 files changed, 16 insertions, 4 deletions
diff --git a/Backend/Api/Api/Models/User.cs b/Backend/Api/Api/Models/User.cs index cf16dbe..52d0f24 100644 --- a/Backend/Api/Api/Models/User.cs +++ b/Backend/Api/Api/Models/User.cs @@ -21,6 +21,7 @@ namespace Api.Models public List<string> following { get; set; } public int followersCount { get; set; } public int followingCount { get; set; } + public List<string>? favourites { get; set; } } public class Login @@ -68,7 +69,8 @@ namespace Api.Models public List<String> following { get; set; } public int followersCount { get; set; } - public int followingCount { get; set; } + public int followingCount { get; set; } + public List<string>? favourites { get; set; } } diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs index 6d28206..cb59330 100644 --- a/Backend/Api/Api/Services/PostService.cs +++ b/Backend/Api/Api/Services/PostService.cs @@ -557,22 +557,28 @@ namespace Api.Services { string userId = _httpContext.HttpContext.User.FindFirstValue("id"); var result = false; + var user = await _users.Find(x => x._id == userId).FirstOrDefaultAsync(); Post post = await _posts.Find(x => x._id == postId).FirstOrDefaultAsync(); if (userId == null || post==null) return result; if (post.favourites == null) post.favourites = new List<string>(); + if(user.favourites==null) + user.favourites= new List<string>(); if (post.favourites.Contains(userId)) { post.favourites.Remove(userId); + user.favourites.Remove(post._id); result = false; } else { post.favourites.Add(userId); + user.favourites.Add(post._id); result = true; } + await _users.ReplaceOneAsync(x => x._id == user._id, user); await _posts.ReplaceOneAsync(x => x._id == postId, post); return result; diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs index 781afa8..2b3f0b8 100644 --- a/Backend/Api/Api/Services/UserService.cs +++ b/Backend/Api/Api/Services/UserService.cs @@ -17,9 +17,7 @@ namespace Api.Services private readonly IMongoCollection<Post> _posts; private readonly IJwtService _jwtService; private IConfiguration _configuration; - private readonly IFileService _fileService; - - private readonly IMongoCollection<UserSend> _usersSend; + private readonly IFileService _fileService; public UserService(IDatabaseConnection settings, IMongoClient mongoClient, IJwtService jwtService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration, IFileService fileService) { var database = mongoClient.GetDatabase(settings.DatabaseName); @@ -364,6 +362,7 @@ namespace Api.Services tosend.followingCount = user.followingCount; tosend.followers = user.followers; tosend.following = user.following; + tosend.favourites = user.favourites; var userposts = await _posts.Find(x => x.ownerId == user._id).ToListAsync(); tosend.postcount = userposts.Count(); return tosend; @@ -384,6 +383,7 @@ namespace Api.Services tosend.followingCount = user.followingCount; tosend.followers = user.followers; tosend.following = user.following; + tosend.favourites = user.favourites; var userposts = await _posts.Find(x => x.ownerId == user._id).ToListAsync(); tosend.postcount = userposts.Count(); return tosend; @@ -476,6 +476,7 @@ namespace Api.Services follower.followers = utemp.followers; follower.followersCount = utemp.followersCount; follower.followingCount = utemp.followingCount; + follower.favourites = utemp.favourites; follower._id = utemp._id; @@ -515,6 +516,7 @@ namespace Api.Services follower._id = utemp._id; follower.followersCount = utemp.followersCount; follower.followingCount = utemp.followingCount; + follower.favourites = utemp.favourites; following.Add((UserSend)follower); } @@ -558,6 +560,7 @@ namespace Api.Services following._id = utemp._id; following.followersCount = utemp.followersCount; following.followingCount = utemp.followingCount; + following.favourites=utemp.favourites; myFollowings.Add((UserSend)following); } @@ -672,6 +675,7 @@ namespace Api.Services follower.followersCount = utemp.followersCount; follower.followingCount = utemp.followingCount; follower._id = utemp._id; + follower.favourites = utemp.favourites; myfollowers.Add((UserSend)follower); } return myfollowers; |