diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-28 20:20:41 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-28 20:20:41 +0200 |
| commit | 702e947c20cbdc2c5aaacfa0e8172bfc97912dd2 (patch) | |
| tree | 4b2569ff82383658cd3e8dc3c8fa91c8785337a0 /src | |
| parent | 9fd19d0c584fb07107319d07c9a5b571a4ab47dd (diff) | |
| download | DevHive-702e947c20cbdc2c5aaacfa0e8172bfc97912dd2.tar DevHive-702e947c20cbdc2c5aaacfa0e8172bfc97912dd2.tar.gz DevHive-702e947c20cbdc2c5aaacfa0e8172bfc97912dd2.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/DevHive.Data/Repositories/CommentRepository.cs | 2 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/FeedRepository.cs | 2 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/PostRepository.cs | 2 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/PostService.cs | 22 |
4 files changed, 19 insertions, 9 deletions
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<Comment> 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<Post> 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<Post> 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<Post>(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<Comment>(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<ReadPostServiceModel>(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<ReadCommentServiceModel>(comment); @@ -113,6 +118,8 @@ namespace DevHive.Services.Services Post post = this._postMapper.Map<Post>(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<Comment>(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)) |
