From ff91162eb83dcf19402240ae8fa06f70cbf2b9e0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 11:31:21 +0200 Subject: Separated comment models, controler and service from post's --- .../Configurations/Mapping/CommentMappings.cs | 2 +- .../Configurations/Mapping/PostMappings.cs | 2 +- src/DevHive.Services/Interfaces/ICommentService.cs | 20 +++ src/DevHive.Services/Interfaces/IPostService.cs | 10 +- .../Models/Comment/CreateCommentServiceModel.cs | 13 ++ .../Models/Comment/ReadCommentServiceModel.cs | 21 +++ .../Models/Comment/UpdateCommentServiceModel.cs | 15 ++ .../Models/Feed/ReadPageServiceModel.cs | 2 +- .../Post/Comment/CreateCommentServiceModel.cs | 13 -- .../Models/Post/Comment/ReadCommentServiceModel.cs | 21 --- .../Post/Comment/UpdateCommentServiceModel.cs | 15 -- .../Models/Post/CreatePostServiceModel.cs | 15 ++ .../Models/Post/Post/CreatePostServiceModel.cs | 15 -- .../Models/Post/Post/ReadPostServiceModel.cs | 26 ---- .../Models/Post/Post/UpdatePostServiceModel.cs | 17 --- .../Models/Post/ReadPostServiceModel.cs | 26 ++++ .../Models/Post/UpdatePostServiceModel.cs | 17 +++ src/DevHive.Services/Services/CommentService.cs | 156 +++++++++++++++++++++ src/DevHive.Services/Services/FeedService.cs | 2 +- src/DevHive.Services/Services/PostService.cs | 72 +--------- .../Extensions/ConfigureDependencyInjection.cs | 4 +- .../Configurations/Mapping/CommentMappings.cs | 7 +- .../Configurations/Mapping/PostMappings.cs | 4 +- src/DevHive.Web/Controllers/CommentController.cs | 82 +++++++++++ src/DevHive.Web/Controllers/PostController.cs | 67 +-------- .../Models/Comment/CreateCommentWebModel.cs | 17 +++ .../Models/Comment/ReadCommentWebModel.cs | 21 +++ .../Models/Comment/UpdateCommentWebModel.cs | 13 ++ src/DevHive.Web/Models/Feed/ReadPageWebModel.cs | 2 +- .../Models/Post/Comment/CreateCommentWebModel.cs | 17 --- .../Models/Post/Comment/ReadCommentWebModel.cs | 21 --- .../Models/Post/Comment/UpdateCommentWebModel.cs | 13 -- src/DevHive.Web/Models/Post/CreatePostWebModel.cs | 16 +++ .../Models/Post/Post/CreatePostWebModel.cs | 17 --- .../Models/Post/Post/ReadPostWebModel.cs | 26 ---- .../Models/Post/Post/UpdatePostWebModel.cs | 21 --- src/DevHive.Web/Models/Post/ReadPostWebModel.cs | 26 ++++ src/DevHive.Web/Models/Post/UpdatePostWebModel.cs | 21 +++ 38 files changed, 497 insertions(+), 378 deletions(-) create mode 100644 src/DevHive.Services/Interfaces/ICommentService.cs create mode 100644 src/DevHive.Services/Models/Comment/CreateCommentServiceModel.cs create mode 100644 src/DevHive.Services/Models/Comment/ReadCommentServiceModel.cs create mode 100644 src/DevHive.Services/Models/Comment/UpdateCommentServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Comment/CreateCommentServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Comment/ReadCommentServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Comment/UpdateCommentServiceModel.cs create mode 100644 src/DevHive.Services/Models/Post/CreatePostServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs create mode 100644 src/DevHive.Services/Models/Post/ReadPostServiceModel.cs create mode 100644 src/DevHive.Services/Models/Post/UpdatePostServiceModel.cs create mode 100644 src/DevHive.Services/Services/CommentService.cs create mode 100644 src/DevHive.Web/Controllers/CommentController.cs create mode 100644 src/DevHive.Web/Models/Comment/CreateCommentWebModel.cs create mode 100644 src/DevHive.Web/Models/Comment/ReadCommentWebModel.cs create mode 100644 src/DevHive.Web/Models/Comment/UpdateCommentWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Comment/CreateCommentWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Comment/ReadCommentWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs create mode 100644 src/DevHive.Web/Models/Post/CreatePostWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs create mode 100644 src/DevHive.Web/Models/Post/ReadPostWebModel.cs create mode 100644 src/DevHive.Web/Models/Post/UpdatePostWebModel.cs diff --git a/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs b/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs index ac3c8f6..a43b64e 100644 --- a/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs @@ -1,6 +1,6 @@ using DevHive.Data.Models; using AutoMapper; -using DevHive.Services.Models.Post.Comment; +using DevHive.Services.Models.Comment; namespace DevHive.Services.Configurations.Mapping { diff --git a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs index c7466d9..81e6ecc 100644 --- a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -1,6 +1,6 @@ using DevHive.Data.Models; using AutoMapper; -using DevHive.Services.Models.Post.Post; +using DevHive.Services.Models.Post; namespace DevHive.Services.Configurations.Mapping { diff --git a/src/DevHive.Services/Interfaces/ICommentService.cs b/src/DevHive.Services/Interfaces/ICommentService.cs new file mode 100644 index 0000000..e7409a8 --- /dev/null +++ b/src/DevHive.Services/Interfaces/ICommentService.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using DevHive.Services.Models.Comment; + +namespace DevHive.Services.Interfaces +{ + public interface ICommentService + { + Task AddComment(CreateCommentServiceModel createPostServiceModel); + + Task GetCommentById(Guid id); + + Task UpdateComment(UpdateCommentServiceModel updateCommentServiceModel); + + Task DeleteComment(Guid id); + + Task ValidateJwtForCreating(Guid userId, string rawTokenData); + Task ValidateJwtForComment(Guid commentId, string rawTokenData); + } +} diff --git a/src/DevHive.Services/Interfaces/IPostService.cs b/src/DevHive.Services/Interfaces/IPostService.cs index 71b558c..d35acfd 100644 --- a/src/DevHive.Services/Interfaces/IPostService.cs +++ b/src/DevHive.Services/Interfaces/IPostService.cs @@ -1,26 +1,20 @@ using System; using System.Threading.Tasks; -using DevHive.Services.Models.Post.Comment; -using DevHive.Services.Models.Post.Post; +using DevHive.Services.Models.Post; namespace DevHive.Services.Interfaces { - public interface IPostService + public interface IPostService { Task CreatePost(CreatePostServiceModel createPostServiceModel); - Task AddComment(CreateCommentServiceModel createPostServiceModel); Task GetPostById(Guid id); - Task GetCommentById(Guid id); Task UpdatePost(UpdatePostServiceModel updatePostServiceModel); - Task UpdateComment(UpdateCommentServiceModel updateCommentServiceModel); Task DeletePost(Guid id); - Task DeleteComment(Guid id); Task ValidateJwtForCreating(Guid userId, string rawTokenData); Task ValidateJwtForPost(Guid postId, string rawTokenData); - Task ValidateJwtForComment(Guid commentId, string rawTokenData); } } diff --git a/src/DevHive.Services/Models/Comment/CreateCommentServiceModel.cs b/src/DevHive.Services/Models/Comment/CreateCommentServiceModel.cs new file mode 100644 index 0000000..30e919b --- /dev/null +++ b/src/DevHive.Services/Models/Comment/CreateCommentServiceModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace DevHive.Services.Models.Comment +{ + public class CreateCommentServiceModel + { + public Guid PostId { get; set; } + + public Guid CreatorId { get; set; } + + public string Message { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Comment/ReadCommentServiceModel.cs b/src/DevHive.Services/Models/Comment/ReadCommentServiceModel.cs new file mode 100644 index 0000000..3196233 --- /dev/null +++ b/src/DevHive.Services/Models/Comment/ReadCommentServiceModel.cs @@ -0,0 +1,21 @@ +using System; + +namespace DevHive.Services.Models.Comment +{ + public class ReadCommentServiceModel + { + public Guid CommentId { get; set; } + + public string IssuerFirstName { get; set; } + + public string IssuerLastName { get; set; } + + public string IssuerUsername { get; set; } + + public Guid PostId { get; set; } + + public string Message { get; set; } + + public DateTime TimeCreated { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Comment/UpdateCommentServiceModel.cs b/src/DevHive.Services/Models/Comment/UpdateCommentServiceModel.cs new file mode 100644 index 0000000..3b78200 --- /dev/null +++ b/src/DevHive.Services/Models/Comment/UpdateCommentServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models.Comment +{ + public class UpdateCommentServiceModel + { + public Guid CreatorId { get; set; } + + public Guid CommentId { get; set; } + + public Guid PostId { get; set; } + + public string NewMessage { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs b/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs index f291de7..95f6845 100644 --- a/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs +++ b/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using DevHive.Services.Models.Post.Post; +using DevHive.Services.Models.Post; namespace DevHive.Services.Models { diff --git a/src/DevHive.Services/Models/Post/Comment/CreateCommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/CreateCommentServiceModel.cs deleted file mode 100644 index 8d49659..0000000 --- a/src/DevHive.Services/Models/Post/Comment/CreateCommentServiceModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Comment -{ - public class CreateCommentServiceModel - { - public Guid PostId { get; set; } - - public Guid CreatorId { get; set; } - - public string Message { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/Comment/ReadCommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/ReadCommentServiceModel.cs deleted file mode 100644 index 12e29a0..0000000 --- a/src/DevHive.Services/Models/Post/Comment/ReadCommentServiceModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Comment -{ - public class ReadCommentServiceModel - { - public Guid CommentId { get; set; } - - public string IssuerFirstName { get; set; } - - public string IssuerLastName { get; set; } - - public string IssuerUsername { get; set; } - - public Guid PostId { get; set; } - - public string Message { get; set; } - - public DateTime TimeCreated { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/Comment/UpdateCommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/UpdateCommentServiceModel.cs deleted file mode 100644 index 3827d4d..0000000 --- a/src/DevHive.Services/Models/Post/Comment/UpdateCommentServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Comment -{ - public class UpdateCommentServiceModel - { - public Guid CreatorId { get; set; } - - public Guid CommentId { get; set; } - - public Guid PostId { get; set; } - - public string NewMessage { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/CreatePostServiceModel.cs b/src/DevHive.Services/Models/Post/CreatePostServiceModel.cs new file mode 100644 index 0000000..304eb90 --- /dev/null +++ b/src/DevHive.Services/Models/Post/CreatePostServiceModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Services.Models.Post +{ + public class CreatePostServiceModel + { + public Guid CreatorId { get; set; } + + public string Message { get; set; } + + public List Files { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs deleted file mode 100644 index 8676f6c..0000000 --- a/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; - -namespace DevHive.Services.Models.Post.Post -{ - public class CreatePostServiceModel - { - public Guid CreatorId { get; set; } - - public string Message { get; set; } - - public List Files { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs deleted file mode 100644 index f0a4fe5..0000000 --- a/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using DevHive.Services.Models.Post.Comment; -using Microsoft.Extensions.FileProviders; - -namespace DevHive.Services.Models.Post.Post -{ - public class ReadPostServiceModel - { - public Guid PostId { get; set; } - - public string CreatorFirstName { get; set; } - - public string CreatorLastName { get; set; } - - public string CreatorUsername { get; set; } - - public string Message { get; set; } - - public DateTime TimeCreated { get; set; } - - public List Comments { get; set; } = new(); - - public List Files { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs deleted file mode 100644 index 24b0b74..0000000 --- a/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; - -namespace DevHive.Services.Models.Post.Post -{ - public class UpdatePostServiceModel - { - public Guid PostId { get; set; } - - public Guid CreatorId { get; set; } - - public string NewMessage { get; set; } - - public List Files { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/ReadPostServiceModel.cs b/src/DevHive.Services/Models/Post/ReadPostServiceModel.cs new file mode 100644 index 0000000..04ec6bd --- /dev/null +++ b/src/DevHive.Services/Models/Post/ReadPostServiceModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using DevHive.Services.Models.Comment; +using Microsoft.Extensions.FileProviders; + +namespace DevHive.Services.Models.Post +{ + public class ReadPostServiceModel + { + public Guid PostId { get; set; } + + public string CreatorFirstName { get; set; } + + public string CreatorLastName { get; set; } + + public string CreatorUsername { get; set; } + + public string Message { get; set; } + + public DateTime TimeCreated { get; set; } + + public List Comments { get; set; } = new(); + + public List Files { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Post/UpdatePostServiceModel.cs b/src/DevHive.Services/Models/Post/UpdatePostServiceModel.cs new file mode 100644 index 0000000..51b16bc --- /dev/null +++ b/src/DevHive.Services/Models/Post/UpdatePostServiceModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Services.Models.Post +{ + public class UpdatePostServiceModel + { + public Guid PostId { get; set; } + + public Guid CreatorId { get; set; } + + public string NewMessage { get; set; } + + public List Files { get; set; } + } +} diff --git a/src/DevHive.Services/Services/CommentService.cs b/src/DevHive.Services/Services/CommentService.cs new file mode 100644 index 0000000..e0eb88a --- /dev/null +++ b/src/DevHive.Services/Services/CommentService.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Data.Models; +using DevHive.Services.Models.Comment; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using DevHive.Services.Interfaces; +using DevHive.Data.Interfaces.Repositories; +using System.Linq; + +namespace DevHive.Services.Services +{ + public class CommentService : ICommentService + { + private readonly IUserRepository _userRepository; + private readonly IPostRepository _postRepository; + private readonly ICommentRepository _commentRepository; + private readonly IMapper _postMapper; + + public CommentService(IUserRepository userRepository, IPostRepository postRepository, ICommentRepository commentRepository, IMapper postMapper) + { + this._userRepository = userRepository; + this._postRepository = postRepository; + this._commentRepository = commentRepository; + this._postMapper = postMapper; + } + + #region Create + public async Task AddComment(CreateCommentServiceModel createCommentServiceModel) + { + if (!await this._postRepository.DoesPostExist(createCommentServiceModel.PostId)) + throw new ArgumentException("Post does not exist!"); + + 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.Creator.Id, comment.TimeCreated); + + return newComment.Id; + } + else + return Guid.Empty; + } + #endregion + + #region Read + public async Task GetCommentById(Guid id) + { + Comment comment = await this._commentRepository.GetByIdAsync(id) ?? + throw new ArgumentException("The comment does not exist"); + + User user = await this._userRepository.GetByIdAsync(comment.Creator.Id) ?? + throw new ArgumentException("The user does not exist"); + + ReadCommentServiceModel readCommentServiceModel = this._postMapper.Map(comment); + readCommentServiceModel.IssuerFirstName = user.FirstName; + readCommentServiceModel.IssuerLastName = user.LastName; + readCommentServiceModel.IssuerUsername = user.UserName; + + return readCommentServiceModel; + } + #endregion + + #region Update + public async Task UpdateComment(UpdateCommentServiceModel updateCommentServiceModel) + { + if (!await this._commentRepository.DoesCommentExist(updateCommentServiceModel.CommentId)) + throw new ArgumentException("Comment does not exist!"); + + 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) + return (await this._commentRepository.GetByIdAsync(updateCommentServiceModel.CommentId)).Id; + else + return Guid.Empty; + } + #endregion + + #region Delete + public async Task DeleteComment(Guid id) + { + if (!await this._commentRepository.DoesCommentExist(id)) + throw new ArgumentException("Comment does not exist!"); + + Comment comment = await this._commentRepository.GetByIdAsync(id); + return await this._commentRepository.DeleteAsync(comment); + } + #endregion + + #region Validations + public async Task ValidateJwtForCreating(Guid userId, string rawTokenData) + { + User user = await this.GetUserForValidation(rawTokenData); + + return user.Id == userId; + } + + public async Task ValidateJwtForComment(Guid commentId, string rawTokenData) + { + Comment comment = await this._commentRepository.GetByIdAsync(commentId) ?? + throw new ArgumentException("Comment does not exist!"); + User user = await this.GetUserForValidation(rawTokenData); + + //If user made the comment + if (comment.Creator.Id == user.Id) + return true; + //If user is admin + else if (user.Roles.Any(x => x.Name == Role.AdminRole)) + return true; + else + return false; + } + + private async Task GetUserForValidation(string rawTokenData) + { + JwtSecurityToken jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); + + Guid jwtUserId = Guid.Parse(this.GetClaimTypeValues("ID", jwt.Claims).First()); + //HashSet jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); + + User user = await this._userRepository.GetByIdAsync(jwtUserId) ?? + throw new ArgumentException("User does not exist!"); + + return user; + } + + + private List GetClaimTypeValues(string type, IEnumerable claims) + { + List toReturn = new(); + + foreach (var claim in claims) + if (claim.Type == type) + toReturn.Add(claim.Value); + + return toReturn; + } + #endregion + } +} + diff --git a/src/DevHive.Services/Services/FeedService.cs b/src/DevHive.Services/Services/FeedService.cs index 1bddac4..269471e 100644 --- a/src/DevHive.Services/Services/FeedService.cs +++ b/src/DevHive.Services/Services/FeedService.cs @@ -7,7 +7,7 @@ using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Services.Interfaces; using DevHive.Services.Models; -using DevHive.Services.Models.Post.Post; +using DevHive.Services.Models.Post; namespace DevHive.Services.Services { diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 7ce7b58..0eaac94 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -3,8 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using DevHive.Data.Models; -using DevHive.Services.Models.Post.Comment; -using DevHive.Services.Models.Post.Post; +using DevHive.Services.Models.Post; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using DevHive.Services.Interfaces; @@ -13,7 +12,7 @@ using System.Linq; namespace DevHive.Services.Services { - public class PostService : IPostService + public class PostService : IPostService { private readonly ICloudService _cloudService; private readonly IUserRepository _userRepository; @@ -55,29 +54,6 @@ namespace DevHive.Services.Services else return Guid.Empty; } - - public async Task AddComment(CreateCommentServiceModel createCommentServiceModel) - { - if (!await this._postRepository.DoesPostExist(createCommentServiceModel.PostId)) - throw new ArgumentException("Post does not exist!"); - - 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.Creator.Id, comment.TimeCreated); - - return newComment.Id; - } - else - return Guid.Empty; - } #endregion #region Read @@ -96,22 +72,6 @@ namespace DevHive.Services.Services return readPostServiceModel; } - - public async Task GetCommentById(Guid id) - { - Comment comment = await this._commentRepository.GetByIdAsync(id) ?? - throw new ArgumentException("The comment does not exist"); - - User user = await this._userRepository.GetByIdAsync(comment.Creator.Id) ?? - throw new ArgumentException("The user does not exist"); - - ReadCommentServiceModel readCommentServiceModel = this._postMapper.Map(comment); - readCommentServiceModel.IssuerFirstName = user.FirstName; - readCommentServiceModel.IssuerLastName = user.LastName; - readCommentServiceModel.IssuerUsername = user.UserName; - - return readCommentServiceModel; - } #endregion #region Update @@ -146,25 +106,6 @@ namespace DevHive.Services.Services else return Guid.Empty; } - - public async Task UpdateComment(UpdateCommentServiceModel updateCommentServiceModel) - { - if (!await this._commentRepository.DoesCommentExist(updateCommentServiceModel.CommentId)) - throw new ArgumentException("Comment does not exist!"); - - 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) - return (await this._commentRepository.GetByIdAsync(updateCommentServiceModel.CommentId)).Id; - else - return Guid.Empty; - } #endregion #region Delete @@ -185,15 +126,6 @@ namespace DevHive.Services.Services return await this._postRepository.DeleteAsync(post); } - - public async Task DeleteComment(Guid id) - { - if (!await this._commentRepository.DoesCommentExist(id)) - throw new ArgumentException("Comment does not exist!"); - - Comment comment = await this._commentRepository.GetByIdAsync(id); - return await this._commentRepository.DeleteAsync(comment); - } #endregion #region Validations diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index fe2c788..8ba0d69 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -1,5 +1,4 @@ using DevHive.Data.Interfaces.Repositories; -using DevHive.Data.Models; using DevHive.Data.Repositories; using DevHive.Services.Interfaces; using DevHive.Services.Services; @@ -8,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection; namespace DevHive.Web.Configurations.Extensions { - public static class ConfigureDependencyInjection + public static class ConfigureDependencyInjection { public static void DependencyInjectionConfiguration(this IServiceCollection services, IConfiguration configuration) { @@ -25,6 +24,7 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(options => new CloudinaryService( diff --git a/src/DevHive.Web/Configurations/Mapping/CommentMappings.cs b/src/DevHive.Web/Configurations/Mapping/CommentMappings.cs index a28ee16..b8d6829 100644 --- a/src/DevHive.Web/Configurations/Mapping/CommentMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/CommentMappings.cs @@ -1,6 +1,6 @@ using AutoMapper; -using DevHive.Services.Models.Post.Comment; -using DevHive.Web.Models.Post.Comment; +using DevHive.Services.Models.Comment; +using DevHive.Web.Models.Comment; namespace DevHive.Web.Configurations.Mapping { @@ -15,6 +15,3 @@ namespace DevHive.Web.Configurations.Mapping } } } - - - diff --git a/src/DevHive.Web/Configurations/Mapping/PostMappings.cs b/src/DevHive.Web/Configurations/Mapping/PostMappings.cs index bc7bc06..a5b46ee 100644 --- a/src/DevHive.Web/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/PostMappings.cs @@ -1,6 +1,6 @@ using AutoMapper; -using DevHive.Services.Models.Post.Post; -using DevHive.Web.Models.Post.Post; +using DevHive.Services.Models.Post; +using DevHive.Web.Models.Post; namespace DevHive.Web.Configurations.Mapping { diff --git a/src/DevHive.Web/Controllers/CommentController.cs b/src/DevHive.Web/Controllers/CommentController.cs new file mode 100644 index 0000000..ebcb87a --- /dev/null +++ b/src/DevHive.Web/Controllers/CommentController.cs @@ -0,0 +1,82 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using AutoMapper; +using System; +using DevHive.Web.Models.Comment; +using DevHive.Services.Models.Comment; +using Microsoft.AspNetCore.Authorization; +using DevHive.Services.Interfaces; + +namespace DevHive.Web.Controllers +{ + [ApiController] + [Route("/api/[controller]")] + [Authorize(Roles = "User,Admin")] + public class CommentController { + private readonly ICommentService _commentService; + private readonly IMapper _commentMapper; + + public CommentController(ICommentService commentService, IMapper commentMapper) + { + this._commentService = commentService; + this._commentMapper = commentMapper; + } + + [HttpPost] + public async Task AddComment(Guid userId, [FromBody] CreateCommentWebModel createCommentWebModel, [FromHeader] string authorization) + { + if (!await this._commentService.ValidateJwtForCreating(userId, authorization)) + return new UnauthorizedResult(); + + CreateCommentServiceModel createCommentServiceModel = + this._commentMapper.Map(createCommentWebModel); + createCommentServiceModel.CreatorId = userId; + + Guid id = await this._commentService.AddComment(createCommentServiceModel); + + return id == Guid.Empty ? + new BadRequestObjectResult("Could not create comment!") : + new OkObjectResult(new { Id = id }); + } + + [HttpGet] + [AllowAnonymous] + public async Task GetCommentById(Guid id) + { + ReadCommentServiceModel readCommentServiceModel = await this._commentService.GetCommentById(id); + ReadCommentWebModel readCommentWebModel = this._commentMapper.Map(readCommentServiceModel); + + return new OkObjectResult(readCommentWebModel); + } + + [HttpPut] + public async Task UpdateComment(Guid userId, [FromBody] UpdateCommentWebModel updateCommentWebModel, [FromHeader] string authorization) + { + if (!await this._commentService.ValidateJwtForComment(updateCommentWebModel.CommentId, authorization)) + return new UnauthorizedResult(); + + UpdateCommentServiceModel updateCommentServiceModel = + this._commentMapper.Map(updateCommentWebModel); + updateCommentServiceModel.CreatorId = userId; + + Guid id = await this._commentService.UpdateComment(updateCommentServiceModel); + + return id == Guid.Empty ? + new BadRequestObjectResult("Unable to update comment!") : + new OkObjectResult(new { Id = id }); + } + + [HttpDelete] + public async Task DeleteComment(Guid id, [FromHeader] string authorization) + { + if (!await this._commentService.ValidateJwtForComment(id, authorization)) + return new UnauthorizedResult(); + + return await this._commentService.DeleteComment(id) ? + new OkResult() : + new BadRequestObjectResult("Could not delete Comment"); + } + + } +} + diff --git a/src/DevHive.Web/Controllers/PostController.cs b/src/DevHive.Web/Controllers/PostController.cs index fe71519..53adfce 100644 --- a/src/DevHive.Web/Controllers/PostController.cs +++ b/src/DevHive.Web/Controllers/PostController.cs @@ -2,16 +2,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using AutoMapper; using System; -using DevHive.Web.Models.Post.Post; -using DevHive.Services.Models.Post.Post; -using DevHive.Web.Models.Post.Comment; -using DevHive.Services.Models.Post.Comment; +using DevHive.Web.Models.Post; +using DevHive.Services.Models.Post; using Microsoft.AspNetCore.Authorization; using DevHive.Services.Interfaces; namespace DevHive.Web.Controllers { - [ApiController] + [ApiController] [Route("/api/[controller]")] [Authorize(Roles = "User,Admin")] public class PostController @@ -42,24 +40,6 @@ namespace DevHive.Web.Controllers new BadRequestObjectResult("Could not create post!") : new OkObjectResult(new { Id = id }); } - - [HttpPost] - [Route("Comment")] - public async Task AddComment(Guid userId, [FromBody] CreateCommentWebModel createCommentWebModel, [FromHeader] string authorization) - { - if (!await this._postService.ValidateJwtForCreating(userId, authorization)) - return new UnauthorizedResult(); - - CreateCommentServiceModel createCommentServiceModel = - this._postMapper.Map(createCommentWebModel); - createCommentServiceModel.CreatorId = userId; - - Guid id = await this._postService.AddComment(createCommentServiceModel); - - return id == Guid.Empty ? - new BadRequestObjectResult("Could not create comment!") : - new OkObjectResult(new { Id = id }); - } #endregion #region Read @@ -72,17 +52,6 @@ namespace DevHive.Web.Controllers return new OkObjectResult(postWebModel); } - - [HttpGet] - [Route("Comment")] - [AllowAnonymous] - public async Task GetCommentById(Guid id) - { - ReadCommentServiceModel readCommentServiceModel = await this._postService.GetCommentById(id); - ReadCommentWebModel readCommentWebModel = this._postMapper.Map(readCommentServiceModel); - - return new OkObjectResult(readCommentWebModel); - } #endregion #region Update @@ -102,24 +71,6 @@ namespace DevHive.Web.Controllers new BadRequestObjectResult("Unable to update post!") : new OkObjectResult(new { Id = id }); } - - [HttpPut] - [Route("Comment")] - public async Task UpdateComment(Guid userId, [FromBody] UpdateCommentWebModel updateCommentWebModel, [FromHeader] string authorization) - { - if (!await this._postService.ValidateJwtForComment(updateCommentWebModel.CommentId, authorization)) - return new UnauthorizedResult(); - - UpdateCommentServiceModel updateCommentServiceModel = - this._postMapper.Map(updateCommentWebModel); - updateCommentServiceModel.CreatorId = userId; - - Guid id = await this._postService.UpdateComment(updateCommentServiceModel); - - return id == Guid.Empty ? - new BadRequestObjectResult("Unable to update comment!") : - new OkObjectResult(new { Id = id }); - } #endregion #region Delete @@ -133,18 +84,6 @@ namespace DevHive.Web.Controllers new OkResult() : new BadRequestObjectResult("Could not delete Comment"); } - - [HttpDelete] - [Route("Comment")] - public async Task DeleteComment(Guid id, [FromHeader] string authorization) - { - if (!await this._postService.ValidateJwtForComment(id, authorization)) - return new UnauthorizedResult(); - - return await this._postService.DeleteComment(id) ? - new OkResult() : - new BadRequestObjectResult("Could not delete Comment"); - } #endregion } } diff --git a/src/DevHive.Web/Models/Comment/CreateCommentWebModel.cs b/src/DevHive.Web/Models/Comment/CreateCommentWebModel.cs new file mode 100644 index 0000000..8b2bf8d --- /dev/null +++ b/src/DevHive.Web/Models/Comment/CreateCommentWebModel.cs @@ -0,0 +1,17 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; + +namespace DevHive.Web.Models.Comment +{ + public class CreateCommentWebModel + { + [NotNull] + [Required] + public Guid PostId { get; set; } + + [NotNull] + [Required] + public string Message { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Comment/ReadCommentWebModel.cs b/src/DevHive.Web/Models/Comment/ReadCommentWebModel.cs new file mode 100644 index 0000000..4d3aff7 --- /dev/null +++ b/src/DevHive.Web/Models/Comment/ReadCommentWebModel.cs @@ -0,0 +1,21 @@ +using System; + +namespace DevHive.Web.Models.Comment +{ + public class ReadCommentWebModel + { + public Guid CommentId { get; set; } + + public Guid PostId { get; set; } + + public string IssuerFirstName { get; set; } + + public string IssuerLastName { get; set; } + + public string IssuerUsername { get; set; } + + public string Message { get; set; } + + public DateTime TimeCreated { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Comment/UpdateCommentWebModel.cs b/src/DevHive.Web/Models/Comment/UpdateCommentWebModel.cs new file mode 100644 index 0000000..b5d7970 --- /dev/null +++ b/src/DevHive.Web/Models/Comment/UpdateCommentWebModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace DevHive.Web.Models.Comment +{ + public class UpdateCommentWebModel + { + public Guid CommentId { get; set; } + + public Guid PostId { get; set; } + + public string NewMessage { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs b/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs index 40d29c9..839aaa6 100644 --- a/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs +++ b/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using DevHive.Web.Models.Post.Post; +using DevHive.Web.Models.Post; namespace DevHive.Web.Controllers { diff --git a/src/DevHive.Web/Models/Post/Comment/CreateCommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/CreateCommentWebModel.cs deleted file mode 100644 index 85c67bf..0000000 --- a/src/DevHive.Web/Models/Post/Comment/CreateCommentWebModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; - -namespace DevHive.Web.Models.Post.Comment -{ - public class CreateCommentWebModel - { - [NotNull] - [Required] - public Guid PostId { get; set; } - - [NotNull] - [Required] - public string Message { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Comment/ReadCommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/ReadCommentWebModel.cs deleted file mode 100644 index 5320c3c..0000000 --- a/src/DevHive.Web/Models/Post/Comment/ReadCommentWebModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace DevHive.Web.Models.Post.Comment -{ - public class ReadCommentWebModel - { - public Guid CommentId { get; set; } - - public Guid PostId { get; set; } - - public string IssuerFirstName { get; set; } - - public string IssuerLastName { get; set; } - - public string IssuerUsername { get; set; } - - public string Message { get; set; } - - public DateTime TimeCreated { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs deleted file mode 100644 index cb1c60a..0000000 --- a/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace DevHive.Web.Models.Post.Comment -{ - public class UpdateCommentWebModel - { - public Guid CommentId { get; set; } - - public Guid PostId { get; set; } - - public string NewMessage { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/CreatePostWebModel.cs b/src/DevHive.Web/Models/Post/CreatePostWebModel.cs new file mode 100644 index 0000000..256055a --- /dev/null +++ b/src/DevHive.Web/Models/Post/CreatePostWebModel.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Web.Models.Post +{ + public class CreatePostWebModel + { + [NotNull] + [Required] + public string Message { get; set; } + + public List Files { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs deleted file mode 100644 index e35a813..0000000 --- a/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; -using Microsoft.AspNetCore.Http; - -namespace DevHive.Web.Models.Post.Post -{ - public class CreatePostWebModel - { - [NotNull] - [Required] - public string Message { get; set; } - - public List Files { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs b/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs deleted file mode 100644 index 5d4da31..0000000 --- a/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using DevHive.Web.Models.Post.Comment; -using Microsoft.AspNetCore.Http; - -namespace DevHive.Web.Models.Post.Post -{ - public class ReadPostWebModel - { - public Guid PostId { get; set; } - - public string CreatorFirstName { get; set; } - - public string CreatorLastName { get; set; } - - public string CreatorUsername { get; set; } - - public string Message { get; set; } - - public DateTime TimeCreated { get; set; } - - public List Comments { get; set; } - - public List Files { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs deleted file mode 100644 index ac84d2c..0000000 --- a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; -using Microsoft.AspNetCore.Http; - -namespace DevHive.Web.Models.Post.Post -{ - public class UpdatePostWebModel - { - [Required] - [NotNull] - public Guid PostId { get; set; } - - [NotNull] - [Required] - public string NewMessage { get; set; } - - public List Files { get; set; } = new(); - } -} diff --git a/src/DevHive.Web/Models/Post/ReadPostWebModel.cs b/src/DevHive.Web/Models/Post/ReadPostWebModel.cs new file mode 100644 index 0000000..1d2669e --- /dev/null +++ b/src/DevHive.Web/Models/Post/ReadPostWebModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using DevHive.Web.Models.Comment; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Web.Models.Post +{ + public class ReadPostWebModel + { + public Guid PostId { get; set; } + + public string CreatorFirstName { get; set; } + + public string CreatorLastName { get; set; } + + public string CreatorUsername { get; set; } + + public string Message { get; set; } + + public DateTime TimeCreated { get; set; } + + public List Comments { get; set; } + + public List Files { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Post/UpdatePostWebModel.cs b/src/DevHive.Web/Models/Post/UpdatePostWebModel.cs new file mode 100644 index 0000000..a0c9b61 --- /dev/null +++ b/src/DevHive.Web/Models/Post/UpdatePostWebModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Web.Models.Post +{ + public class UpdatePostWebModel + { + [Required] + [NotNull] + public Guid PostId { get; set; } + + [NotNull] + [Required] + public string NewMessage { get; set; } + + public List Files { get; set; } = new(); + } +} -- cgit v1.2.3 From 8b164bf4ac8c307de933b476e858e489a64c0da5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 11:31:48 +0200 Subject: Added cloud implementation migration --- ...20210130092813_CloudinaryFileUpload.Designer.cs | 537 +++++++++++++++++++++ .../20210130092813_CloudinaryFileUpload.cs | 145 ++++++ .../Migrations/DevHiveContextModelSnapshot.cs | 41 +- 3 files changed, 716 insertions(+), 7 deletions(-) create mode 100644 src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.cs diff --git a/src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.Designer.cs b/src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.Designer.cs new file mode 100644 index 0000000..1609c52 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.Designer.cs @@ -0,0 +1,537 @@ +// +using System; +using System.Collections.Generic; +using DevHive.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DevHive.Data.Migrations +{ + [DbContext(typeof(DevHiveContext))] + [Migration("20210130092813_CloudinaryFileUpload")] + partial class CloudinaryFileUpload + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityByDefaultColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Language", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Languages"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Technology", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Technologies"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .HasColumnType("text"); + + b.Property("LastName") + .HasColumnType("text"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.HasIndex("UserId"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("RoleUser", b => + { + b.Property("RolesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("RolesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("RoleUser"); + }); + + modelBuilder.Entity("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany("Friends") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RoleUser", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RolesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.cs b/src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.cs new file mode 100644 index 0000000..f691c9b --- /dev/null +++ b/src/DevHive.Data/Migrations/20210130092813_CloudinaryFileUpload.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class CloudinaryFileUpload : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Comments_Posts_PostId", + table: "Comments"); + + migrationBuilder.AlterColumn( + name: "CreatorId", + table: "Posts", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AddColumn>( + name: "FileUrls", + table: "Posts", + type: "text[]", + nullable: true); + + migrationBuilder.AlterColumn( + name: "PostId", + table: "Comments", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "CreatorId", + table: "Comments", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.CreateIndex( + name: "IX_Posts_CreatorId", + table: "Posts", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_CreatorId", + table: "Comments", + column: "CreatorId"); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_AspNetUsers_CreatorId", + table: "Comments", + column: "CreatorId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_Posts_PostId", + table: "Comments", + column: "PostId", + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Posts_AspNetUsers_CreatorId", + table: "Posts", + column: "CreatorId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Comments_AspNetUsers_CreatorId", + table: "Comments"); + + migrationBuilder.DropForeignKey( + name: "FK_Comments_Posts_PostId", + table: "Comments"); + + migrationBuilder.DropForeignKey( + name: "FK_Posts_AspNetUsers_CreatorId", + table: "Posts"); + + migrationBuilder.DropIndex( + name: "IX_Posts_CreatorId", + table: "Posts"); + + migrationBuilder.DropIndex( + name: "IX_Comments_CreatorId", + table: "Comments"); + + migrationBuilder.DropColumn( + name: "FileUrls", + table: "Posts"); + + migrationBuilder.AlterColumn( + name: "CreatorId", + table: "Posts", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "PostId", + table: "Comments", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatorId", + table: "Comments", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_Posts_PostId", + table: "Comments", + column: "PostId", + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs index cf0a82b..f662af7 100644 --- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs +++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs @@ -1,5 +1,6 @@ // using System; +using System.Collections.Generic; using DevHive.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -25,13 +26,13 @@ namespace DevHive.Data.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("CreatorId") + b.Property("CreatorId") .HasColumnType("uuid"); b.Property("Message") .HasColumnType("text"); - b.Property("PostId") + b.Property("PostId") .HasColumnType("uuid"); b.Property("TimeCreated") @@ -39,6 +40,8 @@ namespace DevHive.Data.Migrations b.HasKey("Id"); + b.HasIndex("CreatorId"); + b.HasIndex("PostId"); b.ToTable("Comments"); @@ -64,9 +67,12 @@ namespace DevHive.Data.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("CreatorId") + b.Property("CreatorId") .HasColumnType("uuid"); + b.Property>("FileUrls") + .HasColumnType("text[]"); + b.Property("Message") .HasColumnType("text"); @@ -75,6 +81,8 @@ namespace DevHive.Data.Migrations b.HasKey("Id"); + b.HasIndex("CreatorId"); + b.ToTable("Posts"); }); @@ -364,11 +372,26 @@ namespace DevHive.Data.Migrations modelBuilder.Entity("DevHive.Data.Models.Comment", b => { - b.HasOne("DevHive.Data.Models.Post", null) + b.HasOne("DevHive.Data.Models.User", "Creator") .WithMany("Comments") - .HasForeignKey("PostId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); }); modelBuilder.Entity("DevHive.Data.Models.User", b => @@ -500,7 +523,11 @@ namespace DevHive.Data.Migrations modelBuilder.Entity("DevHive.Data.Models.User", b => { + b.Navigation("Comments"); + b.Navigation("Friends"); + + b.Navigation("Posts"); }); #pragma warning restore 612, 618 } -- cgit v1.2.3 From 19ef5e2cdbad996da58787c0fb22a35ab3dd59e8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 11:44:56 +0200 Subject: Fixed comment and post getting and updating --- src/DevHive.Data/Repositories/CommentRepository.cs | 23 ++++++++++++++++++++ src/DevHive.Data/Repositories/PostRepository.cs | 25 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs index d33b7bf..8ddc628 100644 --- a/src/DevHive.Data/Repositories/CommentRepository.cs +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -17,6 +17,14 @@ namespace DevHive.Data.Repositories } #region Read + public override async Task GetByIdAsync(Guid id) + { + return await this._context.Comments + .Include(x => x.Creator) + .Include(x => x.Post) + .FirstOrDefaultAsync(x => x.Id == id); + } + public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) { return await this._context.Comments @@ -25,6 +33,21 @@ namespace DevHive.Data.Repositories } #endregion + #region Update + public override async Task EditAsync(Guid id, Comment newEntity) + { + Comment comment = await this.GetByIdAsync(id); + + this._context + .Entry(comment) + .CurrentValues + .SetValues(newEntity); + + return await this.SaveChangesAsync(this._context); + } + #endregion + + #region Validations public async Task DoesCommentExist(Guid id) { diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 78b40cd..07b5875 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -23,6 +23,7 @@ namespace DevHive.Data.Repositories { return await this._context.Posts .Include(x => x.Comments) + .Include(x => x.Creator) .FirstOrDefaultAsync(x => x.Id == id); } @@ -39,6 +40,30 @@ namespace DevHive.Data.Repositories } #endregion + #region Update + public override async Task EditAsync(Guid id, Post newEntity) + { + Post post = await this.GetByIdAsync(id); + + this._context + .Entry(post) + .CurrentValues + .SetValues(newEntity); + + post.FileUrls.Clear(); + foreach(var fileUrl in newEntity.FileUrls) + post.FileUrls.Add(fileUrl); + + post.Comments.Clear(); + foreach(var comment in newEntity.Comments) + post.Comments.Add(comment); + + this._context.Entry(post).State = EntityState.Modified; + + return await this.SaveChangesAsync(this._context); + } + #endregion + #region Validations public async Task DoesPostExist(Guid postId) { -- cgit v1.2.3 From b41172567dbfd9be266ece1e47b73aab0c6e9740 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 12:38:13 +0200 Subject: Made profile editing of languages and technologies in profile settings page look a lot better --- .../profile-settings.component.css | 28 +++++++++++++++++ .../profile-settings.component.html | 36 +++++++++++++++------- .../app/components/profile/profile.component.css | 7 ----- src/DevHive.Angular/src/styles.css | 7 +++++ 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.css b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.css index 7e0978d..2aecef5 100644 --- a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.css +++ b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.css @@ -50,12 +50,40 @@ hr { transform: translate(0, -1.2em); } +#all-languages, #all-technologies { + display: flex; + flex-wrap: wrap; +} + +#all-languages > *, #all-technologies > * { + width: fit-content; + margin-top: .1em; + margin-bottom: .1em; +} + /* Buttons */ +.edit-btn { + border-radius: 0 !important; + color: var(--focus-color); + background-color: white; + border-color: var(--focus-color); +} + +.edit-btn:hover { + color: white; + background-color: black; + border-color: black !important; +} + .submit-btn { margin-bottom: .5em; } +#update-profile-btn { + margin-top: 1em; +} + #delete-account:hover { color: indianred; border-color: indianred !important; diff --git a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.html b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.html index 16b537c..1b713d7 100644 --- a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.html +++ b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.html @@ -58,28 +58,42 @@ - +
- Type in your desired languages, separated by a space. - +
+ + +
+ +
+
Available languages: -
- {{ lang.name }} +
+
+ {{ lang.name }} +
- +
- Type in your desired technologies, separated by a space. - +
+ + +
+ +
+
Available technologies: -
- {{ tech.name }} +
+
+ {{ tech.name }} +
- + diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.css b/src/DevHive.Angular/src/app/components/profile/profile.component.css index 7d96624..3f9ede3 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.css +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.css @@ -74,13 +74,6 @@ hr { align-items: center; } -.user-language, .user-technology { - border-radius: .4em; - background-color: lightgrey; - padding: .2em; - margin: 0 .2em; -} - /* Posts */ #posts { diff --git a/src/DevHive.Angular/src/styles.css b/src/DevHive.Angular/src/styles.css index 1320795..aaa1bd5 100644 --- a/src/DevHive.Angular/src/styles.css +++ b/src/DevHive.Angular/src/styles.css @@ -73,6 +73,13 @@ input:focus, button:focus { scrollbar-width: none; /* Firefox */ } +.user-language, .user-technology { + border-radius: .4em; + background-color: lightgrey; + padding: .26em; + margin: 0 .2em; +} + /* Inputs, the type found in login and register */ .input-selection { -- cgit v1.2.3 From 1cf7f72b1b8c4d0c353fd7989de0c44d11009b8c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 12:41:31 +0200 Subject: Fixed successbar error in console --- .../src/app/components/success-bar/success-bar.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/DevHive.Angular/src/app/components/success-bar/success-bar.component.ts b/src/DevHive.Angular/src/app/components/success-bar/success-bar.component.ts index 9a12c3a..f7db0e2 100644 --- a/src/DevHive.Angular/src/app/components/success-bar/success-bar.component.ts +++ b/src/DevHive.Angular/src/app/components/success-bar/success-bar.component.ts @@ -15,7 +15,10 @@ export class SuccessBarComponent implements OnInit { } showMsg(msg?: string | undefined): void { - if (msg === undefined || msg.trim() === '') { + if (msg === undefined) { + this.successMsg = 'Success!'; + } + else if (msg.trim() === '') { this.successMsg = 'Success!'; } else { -- cgit v1.2.3 From a8cc808396a24f0a5e4262d07e3edae1a4e5fc1d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 12:48:51 +0200 Subject: Editing user languages and technologies supports having multiple spaces anywhere in input --- .../app/components/profile-settings/profile-settings.component.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts index 5be160e..1f17fe1 100644 --- a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts @@ -185,7 +185,9 @@ export class ProfileSettingsComponent implements OnInit { // Transfer user input to objects of type { "name": "value" } const actualLanguages = []; for (const lName of names) { - actualLanguages.push({ name : lName }); + if (lName !== '') { + actualLanguages.push({ name : lName }); + } } // Add the data to the form (to the value that is going to be sent) @@ -211,7 +213,9 @@ export class ProfileSettingsComponent implements OnInit { // Transfer user input to objects of type { "name": "value" } const actualTechnologies = []; for (const tName of names) { - actualTechnologies.push({ name : tName }); + if (tName !== '') { + actualTechnologies.push({ name : tName }); + } } // Add the data to the form (to the value that is going to be sent) -- 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(-) 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 387e1698ad1660d321ca48f0699fb3eeb4a86a07 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 13:25:23 +0200 Subject: Fixed authorization requiremenets for geting user posts --- src/DevHive.Web/Controllers/FeedController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DevHive.Web/Controllers/FeedController.cs b/src/DevHive.Web/Controllers/FeedController.cs index b04c37a..3dd6bc9 100644 --- a/src/DevHive.Web/Controllers/FeedController.cs +++ b/src/DevHive.Web/Controllers/FeedController.cs @@ -38,6 +38,7 @@ namespace DevHive.Web.Controllers [HttpGet] [Route("GetUserPosts")] + [AllowAnonymous] public async Task GetUserPosts(string username, [FromBody] GetPageWebModel getPageWebModel) { GetPageServiceModel getPageServiceModel = this._mapper.Map(getPageWebModel); -- cgit v1.2.3 From c8083d23e6f0483ce569845ddb7187c41f7a6e1f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 13:33:55 +0200 Subject: Made feed methods Post, from Get, because get requests mustn't have a body --- src/DevHive.Web/Controllers/FeedController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DevHive.Web/Controllers/FeedController.cs b/src/DevHive.Web/Controllers/FeedController.cs index 3dd6bc9..2f14cf3 100644 --- a/src/DevHive.Web/Controllers/FeedController.cs +++ b/src/DevHive.Web/Controllers/FeedController.cs @@ -23,7 +23,7 @@ namespace DevHive.Web.Controllers this._mapper = mapper; } - [HttpGet] + [HttpPost] [Route("GetPosts")] public async Task GetPosts(Guid userId, [FromBody] GetPageWebModel getPageWebModel) { @@ -36,7 +36,7 @@ namespace DevHive.Web.Controllers return new OkObjectResult(readPageWebModel); } - [HttpGet] + [HttpPost] [Route("GetUserPosts")] [AllowAnonymous] public async Task GetUserPosts(string username, [FromBody] GetPageWebModel getPageWebModel) -- cgit v1.2.3 From c1691aa2373f9b3be26b450aa8b681b54654770d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 14:20:14 +0200 Subject: Made post component dynamic --- .../src/app/app-constants.module.ts | 2 ++ .../src/app/components/post/post.component.html | 6 ++-- .../src/app/components/post/post.component.ts | 18 +++++++++-- .../src/app/services/post.service.ts | 25 +++++++++++++++ src/DevHive.Angular/src/models/post.ts | 37 ++++++++++++++++++++++ 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/DevHive.Angular/src/app/services/post.service.ts create mode 100644 src/DevHive.Angular/src/models/post.ts diff --git a/src/DevHive.Angular/src/app/app-constants.module.ts b/src/DevHive.Angular/src/app/app-constants.module.ts index 7552a5e..8a63651 100644 --- a/src/DevHive.Angular/src/app/app-constants.module.ts +++ b/src/DevHive.Angular/src/app/app-constants.module.ts @@ -8,5 +8,7 @@ export class AppConstants { public static API_LANGUAGE_URL = AppConstants.BASE_API_URL + '/Language'; public static API_TECHNOLOGY_URL = AppConstants.BASE_API_URL + '/Technology'; + public static API_POST_URL = AppConstants.BASE_API_URL + '/Post'; + public static FALLBACK_PROFILE_ICON = 'assets/images/feed/profile-pic.png'; } diff --git a/src/DevHive.Angular/src/app/components/post/post.component.html b/src/DevHive.Angular/src/app/components/post/post.component.html index 487b785..4dec754 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.html +++ b/src/DevHive.Angular/src/app/components/post/post.component.html @@ -1,4 +1,4 @@ -
+
@@ -12,10 +12,10 @@
- Your opinion on my idea? + {{ post.message }}
- 17:41 - 27 Dec 2020 + {{ post.timeCreated }}
diff --git a/src/DevHive.Angular/src/app/components/post/post.component.ts b/src/DevHive.Angular/src/app/components/post/post.component.ts index 76a4873..ab894d1 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.ts +++ b/src/DevHive.Angular/src/app/components/post/post.component.ts @@ -1,7 +1,10 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { Guid } from 'guid-typescript'; import {AppConstants} from 'src/app/app-constants.module'; +import {FeedService} from 'src/app/services/feed.service'; +import {PostService} from 'src/app/services/post.service'; import { User } from 'src/models/identity/user'; +import {Post} from 'src/models/post'; @Component({ selector: 'app-post', @@ -10,11 +13,16 @@ import { User } from 'src/models/identity/user'; }) export class PostComponent implements OnInit { public user: User; + public post: Post; public votesNumber: number; + public loaded = false; + @Input() paramId: string; - constructor() {} + constructor(private _postService: PostService) + {} ngOnInit(): void { + this.post = this._postService.getDefaultPost(); // Fetch data in post service this.user = new User( Guid.create(), @@ -27,6 +35,12 @@ export class PostComponent implements OnInit { new Array() ); + this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( + (result: object) => { + Object.assign(this.post, result); + this.loaded = true; + } + ); this.votesNumber = 23; } } diff --git a/src/DevHive.Angular/src/app/services/post.service.ts b/src/DevHive.Angular/src/app/services/post.service.ts new file mode 100644 index 0000000..74105b3 --- /dev/null +++ b/src/DevHive.Angular/src/app/services/post.service.ts @@ -0,0 +1,25 @@ +import {HttpClient, HttpParams} from '@angular/common/http'; +import {Injectable} from '@angular/core'; +import {Guid} from 'guid-typescript'; +import {Observable} from 'rxjs'; +import {Post} from 'src/models/post'; +import {AppConstants} from '../app-constants.module'; + +@Injectable({ + providedIn: 'root' +}) +export class PostService { + constructor(private http: HttpClient) { } + + getDefaultPost(): Post { + return new Post(Guid.createEmpty(), '', new Date()); + } + + getPostRequest(id: Guid): Observable { + const options = { + params: new HttpParams().set('Id', id.toString()) + }; + return this.http.get(AppConstants.API_POST_URL, options); + } +} + diff --git a/src/DevHive.Angular/src/models/post.ts b/src/DevHive.Angular/src/models/post.ts new file mode 100644 index 0000000..aed1005 --- /dev/null +++ b/src/DevHive.Angular/src/models/post.ts @@ -0,0 +1,37 @@ +import {Guid} from 'guid-typescript'; + +export class Post { + private _postId: Guid; + // _creatorId + private _message: string; + private _timeCreated: Date; + // _comments + // _files + + constructor(postId: Guid, message: string, timeCreated: Date) { + this.postId = postId; + this.message = message; + this.timeCreated = timeCreated; + } + + public get postId(): Guid { + return this._postId; + } + public set postId(v: Guid) { + this._postId = v; + } + + public get message(): string { + return this._message; + } + public set message(v: string) { + this._message = v; + } + + public get timeCreated(): Date { + return this._timeCreated; + } + public set timeCreated(v: Date) { + this._timeCreated = v; + } +} -- cgit v1.2.3 From a9788aafbf3e7df1368d361363cd05f8faa8c6d6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 14:20:48 +0200 Subject: Made user page posts dynamic --- .../src/app/app-constants.module.ts | 1 + .../app/components/profile/profile.component.html | 8 +++++--- .../app/components/profile/profile.component.ts | 19 +++++++++++++++--- .../src/app/services/feed.service.ts | 23 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 src/DevHive.Angular/src/app/services/feed.service.ts diff --git a/src/DevHive.Angular/src/app/app-constants.module.ts b/src/DevHive.Angular/src/app/app-constants.module.ts index 8a63651..28540c4 100644 --- a/src/DevHive.Angular/src/app/app-constants.module.ts +++ b/src/DevHive.Angular/src/app/app-constants.module.ts @@ -9,6 +9,7 @@ export class AppConstants { public static API_TECHNOLOGY_URL = AppConstants.BASE_API_URL + '/Technology'; public static API_POST_URL = AppConstants.BASE_API_URL + '/Post'; + public static API_FEED_URL = AppConstants.BASE_API_URL + '/Feed'; public static FALLBACK_PROFILE_ICON = 'assets/images/feed/profile-pic.png'; } diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.html b/src/DevHive.Angular/src/app/components/profile/profile.component.html index 43d580f..8ac91af 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.html +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.html @@ -41,9 +41,11 @@  None -
-
- Posts go here +
+
+
+ +
diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.ts b/src/DevHive.Angular/src/app/components/profile/profile.component.ts index 69d7e72..1a3f0b8 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.ts +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.ts @@ -7,6 +7,8 @@ import {HttpErrorResponse} from '@angular/common/http'; import {Location} from '@angular/common'; import {LanguageService} from 'src/app/services/language.service'; import {TechnologyService} from 'src/app/services/technology.service'; +import {Post} from 'src/models/post'; +import {FeedService} from 'src/app/services/feed.service'; @Component({ selector: 'app-profile', @@ -18,10 +20,11 @@ export class ProfileComponent implements OnInit { public loggedInUser = false; public dataArrived = false; public user: User; + public userPosts: Post[] = []; public showNoLangMsg = false; public showNoTechMsg = false; - constructor(private _router: Router, private _userService: UserService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _location: Location) + constructor(private _router: Router, private _userService: UserService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _feedService: FeedService, private _location: Location) { } private setDefaultUser(): void { @@ -57,11 +60,11 @@ export class ProfileComponent implements OnInit { private loadTechnologies(): void { if (this.user.technologies.length > 0) { - // When user has technologies, get their names and finally finish loading + // When user has technologies, get their names and then load posts this._technologyService.getFullTechnologiesFromIncomplete(this.user.technologies) .then(value => { this.user.technologies = value; - this.finishUserLoading(); + this.loadPosts(); }); } else { @@ -70,6 +73,16 @@ export class ProfileComponent implements OnInit { } } + private loadPosts(): void { + this._feedService.getUserPostsRequest(this.user.userName, 1, '2021-01-29T21:35:30.977Z', 5).subscribe( + (result: object) => { + this.userPosts = Object.values(result)[0]; + console.log(this.userPosts); + this.finishUserLoading(); + } + ); + } + private finishUserLoading(): void { if (this.user.imageUrl === '') { this.user.imageUrl = AppConstants.FALLBACK_PROFILE_ICON; diff --git a/src/DevHive.Angular/src/app/services/feed.service.ts b/src/DevHive.Angular/src/app/services/feed.service.ts new file mode 100644 index 0000000..42757eb --- /dev/null +++ b/src/DevHive.Angular/src/app/services/feed.service.ts @@ -0,0 +1,23 @@ +import {HttpClient, HttpParams} from '@angular/common/http'; +import {Injectable} from '@angular/core'; +import {Observable} from 'rxjs'; +import {AppConstants} from '../app-constants.module'; + +@Injectable({ + providedIn: 'root' +}) +export class FeedService { + constructor(private http: HttpClient) { } + + getUserPostsRequest(userName: string, pageNumber: number, firstTimeIssued: string, pageSize: number): Observable { + const body = { + pageNumber: pageNumber, + firstPageTimeIssued: firstTimeIssued, + pageSize: pageSize + }; + const options = { + params: new HttpParams().set('UserName', userName) + }; + return this.http.post(AppConstants.API_FEED_URL + '/GetUserPosts', body, options); + } +} -- cgit v1.2.3 From 69dc1caca6a3f4ff7bbb5c01dfe23ffdc27f20fc Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 14:20:14 +0200 Subject: Made post component slightly more dynamic (postId, message and time created are dynamic) --- .../src/app/app-constants.module.ts | 2 ++ .../src/app/components/post/post.component.html | 6 ++-- .../src/app/components/post/post.component.ts | 18 +++++++++-- .../src/app/services/post.service.ts | 25 +++++++++++++++ src/DevHive.Angular/src/models/post.ts | 37 ++++++++++++++++++++++ 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/DevHive.Angular/src/app/services/post.service.ts create mode 100644 src/DevHive.Angular/src/models/post.ts diff --git a/src/DevHive.Angular/src/app/app-constants.module.ts b/src/DevHive.Angular/src/app/app-constants.module.ts index 7552a5e..8a63651 100644 --- a/src/DevHive.Angular/src/app/app-constants.module.ts +++ b/src/DevHive.Angular/src/app/app-constants.module.ts @@ -8,5 +8,7 @@ export class AppConstants { public static API_LANGUAGE_URL = AppConstants.BASE_API_URL + '/Language'; public static API_TECHNOLOGY_URL = AppConstants.BASE_API_URL + '/Technology'; + public static API_POST_URL = AppConstants.BASE_API_URL + '/Post'; + public static FALLBACK_PROFILE_ICON = 'assets/images/feed/profile-pic.png'; } diff --git a/src/DevHive.Angular/src/app/components/post/post.component.html b/src/DevHive.Angular/src/app/components/post/post.component.html index 487b785..4dec754 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.html +++ b/src/DevHive.Angular/src/app/components/post/post.component.html @@ -1,4 +1,4 @@ -
+
@@ -12,10 +12,10 @@
- Your opinion on my idea? + {{ post.message }}
- 17:41 - 27 Dec 2020 + {{ post.timeCreated }}
diff --git a/src/DevHive.Angular/src/app/components/post/post.component.ts b/src/DevHive.Angular/src/app/components/post/post.component.ts index 76a4873..ab894d1 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.ts +++ b/src/DevHive.Angular/src/app/components/post/post.component.ts @@ -1,7 +1,10 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { Guid } from 'guid-typescript'; import {AppConstants} from 'src/app/app-constants.module'; +import {FeedService} from 'src/app/services/feed.service'; +import {PostService} from 'src/app/services/post.service'; import { User } from 'src/models/identity/user'; +import {Post} from 'src/models/post'; @Component({ selector: 'app-post', @@ -10,11 +13,16 @@ import { User } from 'src/models/identity/user'; }) export class PostComponent implements OnInit { public user: User; + public post: Post; public votesNumber: number; + public loaded = false; + @Input() paramId: string; - constructor() {} + constructor(private _postService: PostService) + {} ngOnInit(): void { + this.post = this._postService.getDefaultPost(); // Fetch data in post service this.user = new User( Guid.create(), @@ -27,6 +35,12 @@ export class PostComponent implements OnInit { new Array() ); + this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( + (result: object) => { + Object.assign(this.post, result); + this.loaded = true; + } + ); this.votesNumber = 23; } } diff --git a/src/DevHive.Angular/src/app/services/post.service.ts b/src/DevHive.Angular/src/app/services/post.service.ts new file mode 100644 index 0000000..74105b3 --- /dev/null +++ b/src/DevHive.Angular/src/app/services/post.service.ts @@ -0,0 +1,25 @@ +import {HttpClient, HttpParams} from '@angular/common/http'; +import {Injectable} from '@angular/core'; +import {Guid} from 'guid-typescript'; +import {Observable} from 'rxjs'; +import {Post} from 'src/models/post'; +import {AppConstants} from '../app-constants.module'; + +@Injectable({ + providedIn: 'root' +}) +export class PostService { + constructor(private http: HttpClient) { } + + getDefaultPost(): Post { + return new Post(Guid.createEmpty(), '', new Date()); + } + + getPostRequest(id: Guid): Observable { + const options = { + params: new HttpParams().set('Id', id.toString()) + }; + return this.http.get(AppConstants.API_POST_URL, options); + } +} + diff --git a/src/DevHive.Angular/src/models/post.ts b/src/DevHive.Angular/src/models/post.ts new file mode 100644 index 0000000..aed1005 --- /dev/null +++ b/src/DevHive.Angular/src/models/post.ts @@ -0,0 +1,37 @@ +import {Guid} from 'guid-typescript'; + +export class Post { + private _postId: Guid; + // _creatorId + private _message: string; + private _timeCreated: Date; + // _comments + // _files + + constructor(postId: Guid, message: string, timeCreated: Date) { + this.postId = postId; + this.message = message; + this.timeCreated = timeCreated; + } + + public get postId(): Guid { + return this._postId; + } + public set postId(v: Guid) { + this._postId = v; + } + + public get message(): string { + return this._message; + } + public set message(v: string) { + this._message = v; + } + + public get timeCreated(): Date { + return this._timeCreated; + } + public set timeCreated(v: Date) { + this._timeCreated = v; + } +} -- cgit v1.2.3 From 288d9cf688a4273ff7dd213e6d2300978df61ea2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 14:20:48 +0200 Subject: Made user page posts dynamic --- .../src/app/app-constants.module.ts | 1 + .../app/components/profile/profile.component.html | 8 +++++--- .../app/components/profile/profile.component.ts | 19 +++++++++++++++--- .../src/app/services/feed.service.ts | 23 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 src/DevHive.Angular/src/app/services/feed.service.ts diff --git a/src/DevHive.Angular/src/app/app-constants.module.ts b/src/DevHive.Angular/src/app/app-constants.module.ts index 8a63651..28540c4 100644 --- a/src/DevHive.Angular/src/app/app-constants.module.ts +++ b/src/DevHive.Angular/src/app/app-constants.module.ts @@ -9,6 +9,7 @@ export class AppConstants { public static API_TECHNOLOGY_URL = AppConstants.BASE_API_URL + '/Technology'; public static API_POST_URL = AppConstants.BASE_API_URL + '/Post'; + public static API_FEED_URL = AppConstants.BASE_API_URL + '/Feed'; public static FALLBACK_PROFILE_ICON = 'assets/images/feed/profile-pic.png'; } diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.html b/src/DevHive.Angular/src/app/components/profile/profile.component.html index 43d580f..8ac91af 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.html +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.html @@ -41,9 +41,11 @@  None -
-
- Posts go here +
+
+
+ +
diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.ts b/src/DevHive.Angular/src/app/components/profile/profile.component.ts index 69d7e72..1a3f0b8 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.ts +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.ts @@ -7,6 +7,8 @@ import {HttpErrorResponse} from '@angular/common/http'; import {Location} from '@angular/common'; import {LanguageService} from 'src/app/services/language.service'; import {TechnologyService} from 'src/app/services/technology.service'; +import {Post} from 'src/models/post'; +import {FeedService} from 'src/app/services/feed.service'; @Component({ selector: 'app-profile', @@ -18,10 +20,11 @@ export class ProfileComponent implements OnInit { public loggedInUser = false; public dataArrived = false; public user: User; + public userPosts: Post[] = []; public showNoLangMsg = false; public showNoTechMsg = false; - constructor(private _router: Router, private _userService: UserService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _location: Location) + constructor(private _router: Router, private _userService: UserService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _feedService: FeedService, private _location: Location) { } private setDefaultUser(): void { @@ -57,11 +60,11 @@ export class ProfileComponent implements OnInit { private loadTechnologies(): void { if (this.user.technologies.length > 0) { - // When user has technologies, get their names and finally finish loading + // When user has technologies, get their names and then load posts this._technologyService.getFullTechnologiesFromIncomplete(this.user.technologies) .then(value => { this.user.technologies = value; - this.finishUserLoading(); + this.loadPosts(); }); } else { @@ -70,6 +73,16 @@ export class ProfileComponent implements OnInit { } } + private loadPosts(): void { + this._feedService.getUserPostsRequest(this.user.userName, 1, '2021-01-29T21:35:30.977Z', 5).subscribe( + (result: object) => { + this.userPosts = Object.values(result)[0]; + console.log(this.userPosts); + this.finishUserLoading(); + } + ); + } + private finishUserLoading(): void { if (this.user.imageUrl === '') { this.user.imageUrl = AppConstants.FALLBACK_PROFILE_ICON; diff --git a/src/DevHive.Angular/src/app/services/feed.service.ts b/src/DevHive.Angular/src/app/services/feed.service.ts new file mode 100644 index 0000000..42757eb --- /dev/null +++ b/src/DevHive.Angular/src/app/services/feed.service.ts @@ -0,0 +1,23 @@ +import {HttpClient, HttpParams} from '@angular/common/http'; +import {Injectable} from '@angular/core'; +import {Observable} from 'rxjs'; +import {AppConstants} from '../app-constants.module'; + +@Injectable({ + providedIn: 'root' +}) +export class FeedService { + constructor(private http: HttpClient) { } + + getUserPostsRequest(userName: string, pageNumber: number, firstTimeIssued: string, pageSize: number): Observable { + const body = { + pageNumber: pageNumber, + firstPageTimeIssued: firstTimeIssued, + pageSize: pageSize + }; + const options = { + params: new HttpParams().set('UserName', userName) + }; + return this.http.post(AppConstants.API_FEED_URL + '/GetUserPosts', body, options); + } +} -- cgit v1.2.3 From ead8acd6ec1fb88f00ccbe32662efddeb29cd2fd Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 19:05:58 +0200 Subject: Finished implementation of service read post mapping --- src/DevHive.Services/Configurations/Mapping/PostMappings.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs index 81e6ecc..d36dbdd 100644 --- a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -17,10 +17,9 @@ namespace DevHive.Services.Configurations.Mapping CreateMap() .ForMember(dest => dest.PostId, src => src.MapFrom(p => p.Id)) - .ForMember(dest => dest.CreatorFirstName, src => src.Ignore()) - .ForMember(dest => dest.CreatorLastName, src => src.Ignore()) - .ForMember(dest => dest.CreatorUsername, src => src.Ignore()); - //TODO: Map those here /\ + .ForMember(dest => dest.CreatorFirstName, src => src.MapFrom(p => p.Creator.FirstName)) + .ForMember(dest => dest.CreatorLastName, src => src.MapFrom(p => p.Creator.LastName)) + .ForMember(dest => dest.CreatorUsername, src => src.MapFrom(p => p.Creator.UserName)); } } } -- cgit v1.2.3 From afb14fe1ab1b2ccc72debc55e2a457f4090ce887 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 20:10:25 +0200 Subject: Angular post model contains creator info; posts now load their creator's data; improved format of post created date --- .../src/app/components/post/post.component.html | 2 +- .../src/app/components/post/post.component.ts | 28 ++++++++++---------- .../app/components/profile/profile.component.html | 4 +-- .../src/app/services/post.service.ts | 2 +- src/DevHive.Angular/src/models/post.ts | 30 ++++++++++++++++++++-- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/post/post.component.html b/src/DevHive.Angular/src/app/components/post/post.component.html index 4dec754..36783e5 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.html +++ b/src/DevHive.Angular/src/app/components/post/post.component.html @@ -15,7 +15,7 @@ {{ post.message }}
- {{ post.timeCreated }} + {{ timeCreated }}
diff --git a/src/DevHive.Angular/src/app/components/post/post.component.ts b/src/DevHive.Angular/src/app/components/post/post.component.ts index ab894d1..2f5aa81 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.ts +++ b/src/DevHive.Angular/src/app/components/post/post.component.ts @@ -3,6 +3,7 @@ import { Guid } from 'guid-typescript'; import {AppConstants} from 'src/app/app-constants.module'; import {FeedService} from 'src/app/services/feed.service'; import {PostService} from 'src/app/services/post.service'; +import {UserService} from 'src/app/services/user.service'; import { User } from 'src/models/identity/user'; import {Post} from 'src/models/post'; @@ -15,32 +16,33 @@ export class PostComponent implements OnInit { public user: User; public post: Post; public votesNumber: number; + public timeCreated: string; public loaded = false; @Input() paramId: string; - constructor(private _postService: PostService) + constructor(private _postService: PostService, private _userService: UserService) {} ngOnInit(): void { this.post = this._postService.getDefaultPost(); - // Fetch data in post service - this.user = new User( - Guid.create(), - 'gosho_trapov', - 'Gosho', - 'Trapov', - 'gotra@bg.com', - AppConstants.FALLBACK_PROFILE_ICON, - new Array(), - new Array() - ); + this.user = this._userService.getDefaultUser(); this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( (result: object) => { Object.assign(this.post, result); - this.loaded = true; + this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); + this.loadUser(); } ); this.votesNumber = 23; } + + private loadUser(): void { + this._userService.getUserByUsernameRequest(this.post.creatorUsername).subscribe( + (result: object) => { + Object.assign(this.user, result); + this.loaded = true; + } + ); + } } diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.html b/src/DevHive.Angular/src/app/components/profile/profile.component.html index 8ac91af..e20f380 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.html +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.html @@ -43,8 +43,8 @@

-
- +
+
diff --git a/src/DevHive.Angular/src/app/services/post.service.ts b/src/DevHive.Angular/src/app/services/post.service.ts index 74105b3..4cd96bc 100644 --- a/src/DevHive.Angular/src/app/services/post.service.ts +++ b/src/DevHive.Angular/src/app/services/post.service.ts @@ -12,7 +12,7 @@ export class PostService { constructor(private http: HttpClient) { } getDefaultPost(): Post { - return new Post(Guid.createEmpty(), '', new Date()); + return new Post(Guid.createEmpty(), 'Gosho', 'Trapov', 'gosho_trapov', 'Your opinion on my idea?', new Date()); } getPostRequest(id: Guid): Observable { diff --git a/src/DevHive.Angular/src/models/post.ts b/src/DevHive.Angular/src/models/post.ts index aed1005..2d7d79f 100644 --- a/src/DevHive.Angular/src/models/post.ts +++ b/src/DevHive.Angular/src/models/post.ts @@ -2,14 +2,19 @@ import {Guid} from 'guid-typescript'; export class Post { private _postId: Guid; - // _creatorId + private _creatorFirstName: string; + private _creatorLastName: string; + private _creatorUsername: string; private _message: string; private _timeCreated: Date; // _comments // _files - constructor(postId: Guid, message: string, timeCreated: Date) { + constructor(postId: Guid, creatorFirstName: string, creatorLastName: string, creatorUsername: string, message: string, timeCreated: Date) { this.postId = postId; + this.creatorFirstName = creatorFirstName; + this.creatorLastName = creatorLastName; + this.creatorUsername = creatorUsername; this.message = message; this.timeCreated = timeCreated; } @@ -21,6 +26,27 @@ export class Post { this._postId = v; } + public get creatorFirstName(): string { + return this._creatorFirstName; + } + public set creatorFirstName(v: string) { + this._creatorFirstName = v; + } + + public get creatorLastName(): string { + return this._creatorLastName; + } + public set creatorLastName(v: string) { + this._creatorLastName = v; + } + + public get creatorUsername(): string { + return this._creatorUsername; + } + public set creatorUsername(v: string) { + this._creatorUsername = v; + } + public get message(): string { return this._message; } -- 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(-) 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 df80b4929549a01602f47dc58feffa51a00ad609 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:18:43 +0200 Subject: Implemented feed service to get the feed; the posts in the feed page are now loaded (aren't static anymore) --- .../src/app/app-constants.module.ts | 1 + .../src/app/components/feed/feed.component.html | 4 +-- .../src/app/components/feed/feed.component.ts | 29 ++++++++++++++-------- .../src/app/services/feed.service.ts | 25 ++++++++++++++++++- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/DevHive.Angular/src/app/app-constants.module.ts b/src/DevHive.Angular/src/app/app-constants.module.ts index 28540c4..cbb1ec1 100644 --- a/src/DevHive.Angular/src/app/app-constants.module.ts +++ b/src/DevHive.Angular/src/app/app-constants.module.ts @@ -11,5 +11,6 @@ export class AppConstants { public static API_POST_URL = AppConstants.BASE_API_URL + '/Post'; public static API_FEED_URL = AppConstants.BASE_API_URL + '/Feed'; + public static PAGE_SIZE = 5; public static FALLBACK_PROFILE_ICON = 'assets/images/feed/profile-pic.png'; } diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.html b/src/DevHive.Angular/src/app/components/feed/feed.component.html index b82b189..35448b7 100644 --- a/src/DevHive.Angular/src/app/components/feed/feed.component.html +++ b/src/DevHive.Angular/src/app/components/feed/feed.component.html @@ -23,8 +23,8 @@
-
- +
+
diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.ts b/src/DevHive.Angular/src/app/components/feed/feed.component.ts index b027e5b..5093b21 100644 --- a/src/DevHive.Angular/src/app/components/feed/feed.component.ts +++ b/src/DevHive.Angular/src/app/components/feed/feed.component.ts @@ -6,6 +6,7 @@ import { PostComponent } from '../post/post.component'; import { UserService } from '../../services/user.service'; import { AppConstants } from 'src/app/app-constants.module'; import {HttpErrorResponse} from '@angular/common/http'; +import {FeedService} from 'src/app/services/feed.service'; @Component({ selector: 'app-feed', @@ -14,26 +15,24 @@ import {HttpErrorResponse} from '@angular/common/http'; }) export class FeedComponent implements OnInit { private _title = 'Feed'; + private _timeLoaded: string; public dataArrived = false; public user: User; - public posts: PostComponent[]; + public posts: PostComponent[] = []; - constructor(private _titleService: Title, private _router: Router, private _userService: UserService) { + constructor(private _titleService: Title, private _router: Router, private _userService: UserService, private _feedService: FeedService) { this._titleService.setTitle(this._title); } ngOnInit(): void { this.user = this._userService.getDefaultUser(); - this.posts = [ - new PostComponent(), - new PostComponent(), - new PostComponent(), - new PostComponent(), - ]; + const now = new Date(); + now.setHours(now.getHours() + 2); // accounting for eastern european timezone + this._timeLoaded = now.toISOString(); if (sessionStorage.getItem('UserCred')) { this._userService.getUserFromSessionStorageRequest().subscribe( - (res: object) => this.finishUserLoading(res), + (res: object) => this.loadFeed(res), (err: HttpErrorResponse) => this.bailOnBadToken() ); } else { @@ -41,8 +40,18 @@ export class FeedComponent implements OnInit { } } - private finishUserLoading(res: object): void { + private loadFeed(res: object): void { Object.assign(this.user, res); + + this._feedService.getUserFeedFromSessionStorageRequest(1, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe( + (result: object) => { + this.posts = Object.values(result)[0]; + this.finishUserLoading(); + } + ); + } + + private finishUserLoading(): void { if (this.user.imageUrl === '') { this.user.imageUrl = AppConstants.FALLBACK_PROFILE_ICON; } diff --git a/src/DevHive.Angular/src/app/services/feed.service.ts b/src/DevHive.Angular/src/app/services/feed.service.ts index 42757eb..cb82bcd 100644 --- a/src/DevHive.Angular/src/app/services/feed.service.ts +++ b/src/DevHive.Angular/src/app/services/feed.service.ts @@ -1,7 +1,11 @@ -import {HttpClient, HttpParams} from '@angular/common/http'; +import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Injectable} from '@angular/core'; +import {Guid} from 'guid-typescript'; import {Observable} from 'rxjs'; +import {IJWTPayload} from 'src/interfaces/jwt-payload'; import {AppConstants} from '../app-constants.module'; +import jwt_decode from 'jwt-decode'; +import {IUserCredentials} from 'src/interfaces/user-credentials'; @Injectable({ providedIn: 'root' @@ -9,6 +13,25 @@ import {AppConstants} from '../app-constants.module'; export class FeedService { constructor(private http: HttpClient) { } + getUserFeedFromSessionStorageRequest(pageNumber: number, firstTimeIssued: string, pageSize: number): Observable { + const jwt: IJWTPayload = { token: sessionStorage.getItem('UserCred') ?? '' }; + const userCred = jwt_decode(jwt.token); + return this.getUserFeedRequest(userCred.ID, jwt.token, pageNumber, firstTimeIssued, pageSize); + } + + getUserFeedRequest(userId: Guid, authToken: string, pageNumber: number, firstTimeIssued: string, pageSize: number): Observable { + const body = { + pageNumber: pageNumber, + firstPageTimeIssued: firstTimeIssued, + pageSize: pageSize + }; + const options = { + params: new HttpParams().set('UserId', userId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this.http.post(AppConstants.API_FEED_URL + '/GetPosts', body, options); + } + getUserPostsRequest(userName: string, pageNumber: number, firstTimeIssued: string, pageSize: number): Observable { const body = { pageNumber: pageNumber, -- cgit v1.2.3 From 8a8d222c4e8263ae3f5dbd61cf7b1d5dcbcdaf5c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:19:52 +0200 Subject: Fixed profile posts not loading on certain accounts; fixed time at which the posts are requested --- .../src/app/components/profile/profile.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.ts b/src/DevHive.Angular/src/app/components/profile/profile.component.ts index 1a3f0b8..d9f94e8 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.ts +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.ts @@ -69,15 +69,17 @@ export class ProfileComponent implements OnInit { } else { this.showNoTechMsg = true; - this.finishUserLoading(); + this.loadPosts(); } } private loadPosts(): void { - this._feedService.getUserPostsRequest(this.user.userName, 1, '2021-01-29T21:35:30.977Z', 5).subscribe( + const now = new Date(); + now.setHours(now.getHours() + 2); // accounting for eastern europe timezone + + this._feedService.getUserPostsRequest(this.user.userName, 1, now.toISOString(), AppConstants.PAGE_SIZE).subscribe( (result: object) => { this.userPosts = Object.values(result)[0]; - console.log(this.userPosts); this.finishUserLoading(); } ); -- cgit v1.2.3 From e6015b5dcdb81e20531641a2f06cc2ef15439ce8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:26:51 +0200 Subject: Fixed posts array in feed component --- src/DevHive.Angular/src/app/components/feed/feed.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.ts b/src/DevHive.Angular/src/app/components/feed/feed.component.ts index 5093b21..3f197df 100644 --- a/src/DevHive.Angular/src/app/components/feed/feed.component.ts +++ b/src/DevHive.Angular/src/app/components/feed/feed.component.ts @@ -2,11 +2,11 @@ import { Component, OnInit } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { Router } from '@angular/router'; import { User } from 'src/models/identity/user'; -import { PostComponent } from '../post/post.component'; import { UserService } from '../../services/user.service'; import { AppConstants } from 'src/app/app-constants.module'; import {HttpErrorResponse} from '@angular/common/http'; import {FeedService} from 'src/app/services/feed.service'; +import {Post} from 'src/models/post'; @Component({ selector: 'app-feed', @@ -18,7 +18,7 @@ export class FeedComponent implements OnInit { private _timeLoaded: string; public dataArrived = false; public user: User; - public posts: PostComponent[] = []; + public posts: Post[] = []; constructor(private _titleService: Title, private _router: Router, private _userService: UserService, private _feedService: FeedService) { this._titleService.setTitle(this._title); -- cgit v1.2.3 From c9ef07bc23e1187ce06471120dc5d3b325e06869 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:27:43 +0200 Subject: Implemnted ability to click on user profile in post and get redirected to the author profile --- src/DevHive.Angular/src/app/components/post/post.component.css | 4 ++++ src/DevHive.Angular/src/app/components/post/post.component.html | 2 +- src/DevHive.Angular/src/app/components/post/post.component.ts | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/post/post.component.css b/src/DevHive.Angular/src/app/components/post/post.component.css index 5395eb2..c3e3caa 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.css +++ b/src/DevHive.Angular/src/app/components/post/post.component.css @@ -24,6 +24,10 @@ hr { margin-bottom: .2em; } +.author:hover { + cursor: pointer; +} + .author > img { width: 2.2em; height: 2.2em; diff --git a/src/DevHive.Angular/src/app/components/post/post.component.html b/src/DevHive.Angular/src/app/components/post/post.component.html index 36783e5..8fbda35 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.html +++ b/src/DevHive.Angular/src/app/components/post/post.component.html @@ -1,6 +1,6 @@
-
+
diff --git a/src/DevHive.Angular/src/app/components/post/post.component.ts b/src/DevHive.Angular/src/app/components/post/post.component.ts index 2f5aa81..7a6b5c0 100644 --- a/src/DevHive.Angular/src/app/components/post/post.component.ts +++ b/src/DevHive.Angular/src/app/components/post/post.component.ts @@ -1,4 +1,5 @@ import { Component, Input, OnInit } from '@angular/core'; +import {Router} from '@angular/router'; import { Guid } from 'guid-typescript'; import {AppConstants} from 'src/app/app-constants.module'; import {FeedService} from 'src/app/services/feed.service'; @@ -20,7 +21,7 @@ export class PostComponent implements OnInit { public loaded = false; @Input() paramId: string; - constructor(private _postService: PostService, private _userService: UserService) + constructor(private _postService: PostService, private _userService: UserService, private _router: Router) {} ngOnInit(): void { @@ -45,4 +46,8 @@ export class PostComponent implements OnInit { } ); } + + goToAuthorProfile(): void { + this._router.navigate(['/profile/' + this.user.userName]); + } } -- cgit v1.2.3 From b4211aaa5d024cddd3a1d285edbee6f67d71b9fd Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:32:40 +0200 Subject: Fixed "Cannot read property 'hideMsg' of undefined" profile settings page error --- .../src/app/components/profile-settings/profile-settings.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts index 1f17fe1..e348b8b 100644 --- a/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/DevHive.Angular/src/app/components/profile-settings/profile-settings.component.ts @@ -126,8 +126,8 @@ export class ProfileSettingsComponent implements OnInit { .then(value => this.updateUserFormGroup.patchValue({ technologyInput : value })); this.updateUserFormGroup.valueChanges.subscribe(() => { - this._successBar.hideMsg(); - this._errorBar.hideError(); + this._successBar?.hideMsg(); + this._errorBar?.hideError(); }); } -- cgit v1.2.3 From cc46a2fb619faf8f3227d3861c770fb3fbb546f0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:46:15 +0200 Subject: Added a message in feed when none of your friends have posted anything --- src/DevHive.Angular/src/app/components/feed/feed.component.css | 9 +++++++++ src/DevHive.Angular/src/app/components/feed/feed.component.html | 4 ++++ src/DevHive.Angular/src/app/components/feed/feed.component.ts | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.css b/src/DevHive.Angular/src/app/components/feed/feed.component.css index e22693e..f810e83 100644 --- a/src/DevHive.Angular/src/app/components/feed/feed.component.css +++ b/src/DevHive.Angular/src/app/components/feed/feed.component.css @@ -109,6 +109,15 @@ display: none; } +/* Posts */ + +#no-posts-msg { + width: 100%; + margin-top: 1em; + color: gray; + text-align: center; +} + /* Elements, that act as buttons */ #profile-bar > #profile-info:hover, diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.html b/src/DevHive.Angular/src/app/components/feed/feed.component.html index 35448b7..e3c6e83 100644 --- a/src/DevHive.Angular/src/app/components/feed/feed.component.html +++ b/src/DevHive.Angular/src/app/components/feed/feed.component.html @@ -23,6 +23,10 @@
+
+ None of your friends have posted anything yet!
+ Try refreshing your page! +
diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.ts b/src/DevHive.Angular/src/app/components/feed/feed.component.ts index 3f197df..f260fd4 100644 --- a/src/DevHive.Angular/src/app/components/feed/feed.component.ts +++ b/src/DevHive.Angular/src/app/components/feed/feed.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { Router } from '@angular/router'; import { User } from 'src/models/identity/user'; @@ -47,6 +47,9 @@ export class FeedComponent implements OnInit { (result: object) => { this.posts = Object.values(result)[0]; this.finishUserLoading(); + }, + (err: HttpErrorResponse) => { + this.finishUserLoading(); } ); } -- cgit v1.2.3 From c0838d5d100d17d2056f8a3dce4dcda588179427 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:52:32 +0200 Subject: Added a message to user profiles, when the user hasn't posted anything --- .../src/app/components/profile/profile.component.css | 8 +++++++- .../src/app/components/profile/profile.component.html | 3 +++ .../src/app/components/profile/profile.component.ts | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.css b/src/DevHive.Angular/src/app/components/profile/profile.component.css index 3f9ede3..f312ebd 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.css +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.css @@ -76,7 +76,13 @@ hr { /* Posts */ -#posts { +#no-posts { width: 100%; + text-align: center; + color: gray; + margin-top: .2em; } +#posts { + width: 100%; +} diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.html b/src/DevHive.Angular/src/app/components/profile/profile.component.html index e20f380..ebb9ec8 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.html +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.html @@ -43,6 +43,9 @@

+
+ {{ user.firstName }} {{ user.lastName }} hasn't posted anything yet! +
diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.ts b/src/DevHive.Angular/src/app/components/profile/profile.component.ts index d9f94e8..7717505 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.ts +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.ts @@ -81,6 +81,9 @@ export class ProfileComponent implements OnInit { (result: object) => { this.userPosts = Object.values(result)[0]; this.finishUserLoading(); + }, + (err: HttpErrorResponse) => { + this.finishUserLoading(); } ); } -- cgit v1.2.3 From b8743cfdd0515e4d07ea5c926be1d9ade5340a91 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 21:53:16 +0200 Subject: Improved scrolling in profile page --- src/DevHive.Angular/src/app/components/profile/profile.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DevHive.Angular/src/app/components/profile/profile.component.html b/src/DevHive.Angular/src/app/components/profile/profile.component.html index ebb9ec8..ac0c07e 100644 --- a/src/DevHive.Angular/src/app/components/profile/profile.component.html +++ b/src/DevHive.Angular/src/app/components/profile/profile.component.html @@ -42,7 +42,7 @@

-
+
{{ user.firstName }} {{ user.lastName }} hasn't posted anything yet!
-- cgit v1.2.3