From d2bc08c0dcd6f0dc0822333bbb00c9fc851f49cb Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 26 Jan 2021 10:55:25 +0200 Subject: Brief testing of GetPost --- src/DevHive.Data/Repositories/FeedRepository.cs | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/DevHive.Data/Repositories/FeedRepository.cs (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs new file mode 100644 index 0000000..8bf1f9a --- /dev/null +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper.Internal; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.Repositories +{ + public class FeedRepository : IFeedRepository + { + private readonly DevHiveContext _context; + + public FeedRepository(DevHiveContext context) + { + this._context = context; + } + public async Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize) + { + List friendsIds = friendsList.Select(f => f.Id).ToList(); + + List posts = await this._context.Posts + .Where(post => post.TimeCreated < firstRequestIssued) + .Where(p => friendsIds.Contains(p.CreatorId)) + .OrderByDescending(x => x.TimeCreated) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); + + return posts; + } + } +} -- cgit v1.2.3 From d59ac14fa58a3c1171442e09a5a96b95e5bf40b8 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 26 Jan 2021 19:49:13 +0200 Subject: Fixed ChangeTracker; Optimized default role insertion --- src/DevHive.Data/DevHiveContext.cs | 6 ++++++ src/DevHive.Data/Repositories/FeedRepository.cs | 1 + src/DevHive.Data/Repositories/LanguageRepository.cs | 3 ++- src/DevHive.Data/Repositories/TechnologyRepository.cs | 2 +- src/DevHive.Data/Repositories/UserRepository.cs | 3 ++- src/DevHive.Services/Services/TechnologyService.cs | 1 + src/DevHive.Services/Services/UserService.cs | 2 +- 7 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 17e16e7..48a6789 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -30,9 +30,15 @@ namespace DevHive.Data builder.Entity() .HasMany(x => x.Languages); + builder.Entity() + .HasMany(x => x.Users); + builder.Entity() .HasMany(x => x.Technologies); + builder.Entity() + .HasMany(x => x.Users); + builder.Entity() .HasChangeTrackingStrategy(ChangeTrackingStrategy.Snapshot); diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index 8bf1f9a..1b7518d 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -17,6 +17,7 @@ namespace DevHive.Data.Repositories { this._context = context; } + public async Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize) { List friendsIds = friendsList.Select(f => f.Id).ToList(); diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index f2cc67f..7f4b946 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -22,7 +22,6 @@ namespace DevHive.Data.Repositories public async Task GetByNameAsync(string languageName) { return await this._context.Languages - .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == languageName); } @@ -36,12 +35,14 @@ namespace DevHive.Data.Repositories public async Task DoesLanguageNameExistAsync(string languageName) { return await this._context.Languages + .AsNoTracking() .AnyAsync(r => r.Name == languageName); } public async Task DoesLanguageExistAsync(Guid id) { return await this._context.Languages + .AsNoTracking() .AnyAsync(r => r.Id == id); } #endregion diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs index e03291d..7bb43cc 100644 --- a/src/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -22,7 +22,6 @@ namespace DevHive.Data.Repositories public async Task GetByNameAsync(string technologyName) { return await this._context.Technologies - .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == technologyName); } @@ -43,6 +42,7 @@ namespace DevHive.Data.Repositories public async Task DoesTechnologyExistAsync(Guid id) { return await this._context.Technologies + .AsNoTracking() .AnyAsync(x => x.Id == id); } #endregion diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 06bafca..57ae146 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -40,7 +40,6 @@ namespace DevHive.Data.Repositories public async Task GetByUsernameAsync(string username) { return await this._context.Users - .AsNoTracking() .Include(x => x.Friends) .Include(x => x.Roles) .Include(x => x.Languages) @@ -74,9 +73,11 @@ namespace DevHive.Data.Repositories public async Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId) { User user = await this._context.Users + .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == userId); User friend = await this._context.Users + .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == friendId); return user.Friends.Contains(friend); diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index 039cd8a..8f37273 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -49,6 +49,7 @@ namespace DevHive.Services.Services return this._technologyMapper.Map(technology); } + public HashSet GetTechnologies() { HashSet technologies = this._technologyRepository.GetTechnologies(); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index abbecb1..9f4c777 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -77,7 +77,7 @@ namespace DevHive.Services.Services // Set the default role to the user Role defaultRole = await this._roleRepository.GetByNameAsync(Role.DefaultRole); - user.Roles = new HashSet() { defaultRole }; + user.Roles.Add(defaultRole); await this._userRepository.AddAsync(user); -- cgit v1.2.3 From 702e947c20cbdc2c5aaacfa0e8172bfc97912dd2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 28 Jan 2021 20:20:41 +0200 Subject: Updated comments and posts to use Creator.Id, rather than CreatorId; updated service to give Posts and Comments the post and creator objects from db --- src/DevHive.Data/Repositories/CommentRepository.cs | 2 +- src/DevHive.Data/Repositories/FeedRepository.cs | 2 +- src/DevHive.Data/Repositories/PostRepository.cs | 2 +- src/DevHive.Services/Services/PostService.cs | 22 ++++++++++++++++------ 4 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs index 006326a..d33b7bf 100644 --- a/src/DevHive.Data/Repositories/CommentRepository.cs +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -20,7 +20,7 @@ namespace DevHive.Data.Repositories public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) { return await this._context.Comments - .FirstOrDefaultAsync(p => p.CreatorId == issuerId && + .FirstOrDefaultAsync(p => p.Creator.Id == issuerId && p.TimeCreated == timeCreated); } #endregion diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index 1b7518d..efcb8e0 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -24,7 +24,7 @@ namespace DevHive.Data.Repositories List posts = await this._context.Posts .Where(post => post.TimeCreated < firstRequestIssued) - .Where(p => friendsIds.Contains(p.CreatorId)) + .Where(p => friendsIds.Contains(p.Creator.Id)) .OrderByDescending(x => x.TimeCreated) .Skip((pageNumber - 1) * pageSize) .Take(pageSize) diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index e8180de..67988f2 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -27,7 +27,7 @@ namespace DevHive.Data.Repositories public async Task GetPostByCreatorAndTimeCreatedAsync(Guid creatorId, DateTime timeCreated) { return await this._context.Posts - .FirstOrDefaultAsync(p => p.CreatorId == creatorId && + .FirstOrDefaultAsync(p => p.Creator.Id == creatorId && p.TimeCreated == timeCreated); } #endregion diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index c27f40b..c3dc82f 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -37,11 +37,13 @@ namespace DevHive.Services.Services Post post = this._postMapper.Map(createPostServiceModel); post.TimeCreated = DateTime.Now; + post.Creator = await this._userRepository.GetByIdAsync(createPostServiceModel.CreatorId); + bool success = await this._postRepository.AddAsync(post); if (success) { Post newPost = await this._postRepository - .GetPostByCreatorAndTimeCreatedAsync(post.CreatorId, post.TimeCreated); + .GetPostByCreatorAndTimeCreatedAsync(post.Creator.Id, post.TimeCreated); return newPost.Id; } @@ -57,11 +59,14 @@ namespace DevHive.Services.Services Comment comment = this._postMapper.Map(createCommentServiceModel); comment.TimeCreated = DateTime.Now; + comment.Creator = await this._userRepository.GetByIdAsync(createCommentServiceModel.CreatorId); + comment.Post = await this._postRepository.GetByIdAsync(createCommentServiceModel.PostId); + bool success = await this._commentRepository.AddAsync(comment); if (success) { Comment newComment = await this._commentRepository - .GetCommentByIssuerAndTimeCreatedAsync(comment.CreatorId, comment.TimeCreated); + .GetCommentByIssuerAndTimeCreatedAsync(comment.Creator.Id, comment.TimeCreated); return newComment.Id; } @@ -76,7 +81,7 @@ namespace DevHive.Services.Services Post post = await this._postRepository.GetByIdAsync(id) ?? throw new ArgumentException("The post does not exist!"); - User user = await this._userRepository.GetByIdAsync(post.CreatorId) ?? + User user = await this._userRepository.GetByIdAsync(post.Creator.Id) ?? throw new ArgumentException("The user does not exist!"); ReadPostServiceModel readPostServiceModel = this._postMapper.Map(post); @@ -92,7 +97,7 @@ namespace DevHive.Services.Services Comment comment = await this._commentRepository.GetByIdAsync(id) ?? throw new ArgumentException("The comment does not exist"); - User user = await this._userRepository.GetByIdAsync(comment.CreatorId) ?? + User user = await this._userRepository.GetByIdAsync(comment.Creator.Id) ?? throw new ArgumentException("The user does not exist"); ReadCommentServiceModel readCommentServiceModel = this._postMapper.Map(comment); @@ -113,6 +118,8 @@ namespace DevHive.Services.Services Post post = this._postMapper.Map(updatePostServiceModel); post.TimeCreated = DateTime.Now; + post.Creator = await this._userRepository.GetByIdAsync(updatePostServiceModel.CreatorId); + bool result = await this._postRepository.EditAsync(updatePostServiceModel.PostId, post); if (result) @@ -129,6 +136,9 @@ namespace DevHive.Services.Services Comment comment = this._postMapper.Map(updateCommentServiceModel); comment.TimeCreated = DateTime.Now; + comment.Creator = await this._userRepository.GetByIdAsync(updateCommentServiceModel.CreatorId); + comment.Post = await this._postRepository.GetByIdAsync(updateCommentServiceModel.PostId); + bool result = await this._commentRepository.EditAsync(updateCommentServiceModel.CommentId, comment); if (result) @@ -166,7 +176,7 @@ namespace DevHive.Services.Services User user = await this.GetUserForValidation(rawTokenData); //If user made the post - if (post.CreatorId == user.Id) + if (post.Creator.Id == user.Id) return true; //If user is admin else if (user.Roles.Any(x => x.Name == Role.AdminRole)) @@ -182,7 +192,7 @@ namespace DevHive.Services.Services User user = await this.GetUserForValidation(rawTokenData); //If user made the comment - if (comment.CreatorId == user.Id) + if (comment.Creator.Id == user.Id) return true; //If user is admin else if (user.Roles.Any(x => x.Name == Role.AdminRole)) -- cgit v1.2.3 From 498af41f38b14372bd2f5eb9a0add7af95c40168 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 13:07:54 +0200 Subject: Fixed GetUserPosts implementation --- .../Interfaces/Repositories/IFeedRepository.cs | 1 + src/DevHive.Data/Repositories/FeedRepository.cs | 13 ++++++++++++ src/DevHive.Services/Interfaces/IFeedService.cs | 1 + src/DevHive.Services/Services/FeedService.cs | 24 ++++++++++++++++++++++ src/DevHive.Web/Controllers/FeedController.cs | 2 +- 5 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs index e9fd48a..7262510 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs @@ -8,5 +8,6 @@ namespace DevHive.Data.Interfaces.Repositories public interface IFeedRepository { Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize); + Task> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize); } } diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index efcb8e0..7ab9a91 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -32,5 +32,18 @@ namespace DevHive.Data.Repositories return posts; } + + public async Task> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize) + { + List posts = await this._context.Posts + .Where(post => post.TimeCreated < firstRequestIssued) + .Where(p => p.Creator.Id == user.Id) + .OrderByDescending(x => x.TimeCreated) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); + + return posts; + } } } diff --git a/src/DevHive.Services/Interfaces/IFeedService.cs b/src/DevHive.Services/Interfaces/IFeedService.cs index 1edba5a..b507b3b 100644 --- a/src/DevHive.Services/Interfaces/IFeedService.cs +++ b/src/DevHive.Services/Interfaces/IFeedService.cs @@ -6,5 +6,6 @@ namespace DevHive.Services.Interfaces public interface IFeedService { Task GetPage(GetPageServiceModel getPageServiceModel); + Task GetUserPage(GetPageServiceModel model); } } diff --git a/src/DevHive.Services/Services/FeedService.cs b/src/DevHive.Services/Services/FeedService.cs index 269471e..ceb5ebf 100644 --- a/src/DevHive.Services/Services/FeedService.cs +++ b/src/DevHive.Services/Services/FeedService.cs @@ -54,5 +54,29 @@ namespace DevHive.Services.Services return readPageServiceModel; } + + public async Task GetUserPage(GetPageServiceModel model) { + User user = null; + + if (!string.IsNullOrEmpty(model.Username)) + user = await this._userRepository.GetByUsernameAsync(model.Username); + else + throw new ArgumentException("Invalid given data!"); + + if (user == null) + throw new ArgumentException("User doesn't exist!"); + + List posts = await this._feedRepository + .GetUsersPosts(user, model.FirstRequestIssued, model.PageNumber, model.PageSize); + + if (posts.Count <= 0) + throw new ArgumentException("User hasn't posted anything yet!"); + + ReadPageServiceModel readPageServiceModel = new(); + foreach (Post post in posts) + readPageServiceModel.Posts.Add(this._mapper.Map(post)); + + return readPageServiceModel; + } } } diff --git a/src/DevHive.Web/Controllers/FeedController.cs b/src/DevHive.Web/Controllers/FeedController.cs index 4fd3ae9..b04c37a 100644 --- a/src/DevHive.Web/Controllers/FeedController.cs +++ b/src/DevHive.Web/Controllers/FeedController.cs @@ -43,7 +43,7 @@ namespace DevHive.Web.Controllers GetPageServiceModel getPageServiceModel = this._mapper.Map(getPageWebModel); getPageServiceModel.Username = username; - ReadPageServiceModel readPageServiceModel = await this._feedService.GetPage(getPageServiceModel); + ReadPageServiceModel readPageServiceModel = await this._feedService.GetUserPage(getPageServiceModel); ReadPageWebModel readPageWebModel = this._mapper.Map(readPageServiceModel); return new OkObjectResult(readPageWebModel); -- cgit v1.2.3 From 5e07474a813e82dd2071c5d9d233beccbe6a8430 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:15:55 +0200 Subject: Fixed ordering of posts in feed repository --- src/DevHive.Data/Repositories/FeedRepository.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index 7ab9a91..d8170d0 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -25,11 +25,14 @@ namespace DevHive.Data.Repositories List posts = await this._context.Posts .Where(post => post.TimeCreated < firstRequestIssued) .Where(p => friendsIds.Contains(p.Creator.Id)) - .OrderByDescending(x => x.TimeCreated) .Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToListAsync(); + // Ordering by descending can't happen in query, because it doesn't order it + // completely correctly (example: in query these two times are ordered + // like this: 2021-01-30T11:49:45, 2021-01-28T21:37:40.701244) + posts = posts.OrderByDescending(x => x.TimeCreated.ToFileTime()).ToList(); return posts; } @@ -38,11 +41,12 @@ namespace DevHive.Data.Repositories List posts = await this._context.Posts .Where(post => post.TimeCreated < firstRequestIssued) .Where(p => p.Creator.Id == user.Id) - .OrderByDescending(x => x.TimeCreated) .Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToListAsync(); + // Look at GetFriendsPosts on why this is done like this + posts = posts.OrderByDescending(x => x.TimeCreated.ToFileTime()).ToList(); return posts; } } -- cgit v1.2.3 From 77daf9d0b1122034712f6b3b2413519e84746e4c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 31 Jan 2021 09:45:10 +0200 Subject: Fixed getting of feed posts --- src/DevHive.Data/Repositories/FeedRepository.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index d8170d0..304697d 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -25,14 +25,16 @@ namespace DevHive.Data.Repositories List posts = await this._context.Posts .Where(post => post.TimeCreated < firstRequestIssued) .Where(p => friendsIds.Contains(p.Creator.Id)) - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize) .ToListAsync(); // Ordering by descending can't happen in query, because it doesn't order it // completely correctly (example: in query these two times are ordered // like this: 2021-01-30T11:49:45, 2021-01-28T21:37:40.701244) - posts = posts.OrderByDescending(x => x.TimeCreated.ToFileTime()).ToList(); + posts = posts + .OrderByDescending(x => x.TimeCreated.ToFileTime()) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToList(); return posts; } @@ -41,12 +43,14 @@ namespace DevHive.Data.Repositories List posts = await this._context.Posts .Where(post => post.TimeCreated < firstRequestIssued) .Where(p => p.Creator.Id == user.Id) - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize) .ToListAsync(); // Look at GetFriendsPosts on why this is done like this - posts = posts.OrderByDescending(x => x.TimeCreated.ToFileTime()).ToList(); + posts = posts + .OrderByDescending(x => x.TimeCreated.ToFileTime()) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToList(); return posts; } } -- cgit v1.2.3 From f3556d4520479888895a472b0378360d157c6eb8 Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 1 Feb 2021 20:21:07 +0200 Subject: Fixed mapping in FeedService --- src/DevHive.Data/Repositories/FeedRepository.cs | 2 ++ src/DevHive.Services/Services/FeedService.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index 304697d..271c3a5 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -35,6 +35,7 @@ namespace DevHive.Data.Repositories .Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToList(); + return posts; } @@ -51,6 +52,7 @@ namespace DevHive.Data.Repositories .Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToList(); + return posts; } } diff --git a/src/DevHive.Services/Services/FeedService.cs b/src/DevHive.Services/Services/FeedService.cs index 9954da1..92ba3ea 100644 --- a/src/DevHive.Services/Services/FeedService.cs +++ b/src/DevHive.Services/Services/FeedService.cs @@ -45,7 +45,10 @@ namespace DevHive.Services.Services List posts = await this._feedRepository .GetFriendsPosts(friendsList, model.FirstRequestIssued, model.PageNumber, model.PageSize); - ReadPageServiceModel readPageServiceModel = this._mapper.Map(posts); + ReadPageServiceModel readPageServiceModel = new(); + foreach (Post post in posts) + readPageServiceModel.Posts.Add(this._mapper.Map(post)); + return readPageServiceModel; } @@ -63,7 +66,9 @@ namespace DevHive.Services.Services List posts = await this._feedRepository .GetUsersPosts(user, model.FirstRequestIssued, model.PageNumber, model.PageSize); - ReadPageServiceModel readPageServiceModel = this._mapper.Map(posts); + ReadPageServiceModel readPageServiceModel = new(); + foreach (Post post in posts) + readPageServiceModel.Posts.Add(this._mapper.Map(post)); return readPageServiceModel; } -- cgit v1.2.3 From a11d023c0e6557baef6b420771e31f9ac0f4b1e2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 4 Feb 2021 15:00:39 +0200 Subject: Added some XML documentation in data layer --- src/DevHive.Data/Repositories/CommentRepository.cs | 3 +++ src/DevHive.Data/Repositories/FeedRepository.cs | 18 ++++++++++++++++++ src/DevHive.Data/Repositories/LanguageRepository.cs | 3 +++ src/DevHive.Data/Repositories/PostRepository.cs | 3 +++ src/DevHive.Data/Repositories/TechnologyRepository.cs | 3 +++ 5 files changed, 30 insertions(+) (limited to 'src/DevHive.Data/Repositories/FeedRepository.cs') diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs index 382c666..bee7624 100644 --- a/src/DevHive.Data/Repositories/CommentRepository.cs +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -28,6 +28,9 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.Id == id); } + /// + /// This method returns the comment that is made at exactly the given time and by the given creator + /// public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) { return await this._context.Comments diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index 271c3a5..8d3e5e1 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -18,6 +18,15 @@ namespace DevHive.Data.Repositories this._context = context; } + /// + /// This returns a given amount of posts of all given friends, created before "firstRequestIssued", + /// ordered from latest to oldest (time created). + /// PageSize specifies how many posts to get, and pageNumber specifices how many posts to skip (pageNumber * pageSize). + /// + /// This method is used in the feed page. + /// Posts from friends are meant to be gotten in chunks, meaning you get X posts, and then get another amount of posts, + /// that are after the first X posts. + /// public async Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize) { List friendsIds = friendsList.Select(f => f.Id).ToList(); @@ -39,6 +48,15 @@ namespace DevHive.Data.Repositories return posts; } + /// + /// This returns a given amount of posts, that a user has made, created before "firstRequestIssued", + /// ordered from latest to oldest (time created). + /// PageSize specifies how many posts to get, and pageNumber specifices how many posts to skip (pageNumber * pageSize). + /// + /// This method is used in the profile page. + /// Posts from friends are meant to be gotten in chunks, meaning you get X posts, and then get another amount of posts, + /// that are after the first X posts. + /// public async Task> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize) { List posts = await this._context.Posts diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index 7f4b946..31d0b86 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -25,6 +25,9 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.Name == languageName); } + /// + /// Returns all technologies that exist in the database + /// public HashSet GetLanguages() { return this._context.Languages.ToHashSet(); diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 0fec435..ed2fa1b 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -39,6 +39,9 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.Id == id); } + /// + /// This method returns the post that is made at exactly the given time and by the given creator + /// public async Task GetPostByCreatorAndTimeCreatedAsync(Guid creatorId, DateTime timeCreated) { return await this._context.Posts diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs index 7bb43cc..6f0d10f 100644 --- a/src/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -25,6 +25,9 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.Name == technologyName); } + /// + /// Returns all technologies that exist in the database + /// public HashSet GetTechnologies() { return this._context.Technologies.ToHashSet(); -- cgit v1.2.3