diff options
| author | transtrike <transtrike@gmail.com> | 2020-12-17 19:13:01 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2020-12-17 19:13:01 +0200 |
| commit | 94a3b0661106e91ab3a1a523af3c60df131a4f63 (patch) | |
| tree | d186fe6d0ea18bdefd8e37f83a754d155f4598d2 /src/DevHive.Services | |
| parent | f4515fc3ff5fc222a3bdd40c5d4113f9bd79106f (diff) | |
| download | DevHive-94a3b0661106e91ab3a1a523af3c60df131a4f63.tar DevHive-94a3b0661106e91ab3a1a523af3c60df131a4f63.tar.gz DevHive-94a3b0661106e91ab3a1a523af3c60df131a4f63.zip | |
Friends implementation added. UserController/AddAFriend added
Diffstat (limited to 'src/DevHive.Services')
| -rw-r--r-- | src/DevHive.Services/Models/Identity/User/UserServiceModel.cs | 7 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/UserService.cs | 22 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index 576e502..868e7ba 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -1,7 +1,12 @@ +using System.Collections.Generic; +using DevHive.Data.Models; +using DevHive.Services.Models.Identity.Role; + namespace DevHive.Services.Models.Identity.User { public class UserServiceModel : BaseUserServiceModel { - public string Role { get; set;} + public IList<RoleServiceModel> Role { get; set; } = new List<RoleServiceModel>(); + public List<UserServiceModel> Friends { get; set; } = new List<UserServiceModel>(); } } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index bd9eaa6..3e65dab 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -72,7 +72,13 @@ namespace DevHive.Services.Services User user = await this._userRepository.GetByIdAsync(id) ?? throw new ArgumentException("User does not exist!"); - return this._userMapper.Map<UserServiceModel>(user); + //Here User has 1 role + + UserServiceModel model = this._userMapper.Map<UserServiceModel>(user); + + //here model has 0 roles + + return model; } public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel) @@ -105,6 +111,16 @@ namespace DevHive.Services.Services throw new InvalidOperationException("Unable to delete user!"); } + public async Task<bool> AddFriend(Guid userId, Guid friendId) + { + User user = await this._userRepository.GetByIdAsync(userId); + User friend = await this._userRepository.GetByIdAsync(friendId); + + return user != default(User) && friend != default(User) ? + await this._userRepository.AddFriend(user, friend) : + throw new ArgumentException("Invalid user!"); + } + private string GeneratePasswordHash(string password) { return string.Join(string.Empty, SHA512.HashData(Encoding.ASCII.GetBytes(password))); @@ -114,9 +130,9 @@ namespace DevHive.Services.Services { byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret); - List<Claim> claims = new List<Claim>() + List<Claim> claims = new() { - new Claim(ClaimTypes.Role, roles[0].Name) // TODO: add support for mulitple roles + new Claim(ClaimTypes.Role, roles[0].Name) // TODO: add support for multiple roles }; SecurityTokenDescriptor tokenDescriptor = new() |
