diff options
author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-12-07 21:15:58 +0100 |
---|---|---|
committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-12-07 21:15:58 +0100 |
commit | 7d2e70fd3770bf7c8c206f7affa860c06de6b271 (patch) | |
tree | a5fdb93bfe621ea9aa188a997195fcb5a9ad0fb7 | |
parent | fb181ee6537963f7d8d85b51f582d170807c8356 (diff) |
Prosiren model korisnika sa favourite. Dodavanje favourite objave i kod korisnika i kod objave.
-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 | ||||
-rw-r--r-- | Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt | 3 |
4 files changed, 18 insertions, 5 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; diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt index 6e282a9..072be55 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt @@ -34,5 +34,6 @@ data class UserReceive( var following:List<String>, var followingCount:Int, var postIds:List<Int>, - var postNumber:Int + var postNumber:Int, + var favourites:List<String>? )
\ No newline at end of file |