aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-16 10:23:15 +0200
committertranstrike <transtrike@gmail.com>2020-12-16 10:23:15 +0200
commitd80b44003ca03cd09bf28278bf2e243581c00332 (patch)
tree759aedce339e9e467c23bedea1464e3c2384ae35 /src/DevHive.Services
parentdc27cec6b3dd631c0f9a4e482743a053cf766df6 (diff)
downloadDevHive-d80b44003ca03cd09bf28278bf2e243581c00332.tar
DevHive-d80b44003ca03cd09bf28278bf2e243581c00332.tar.gz
DevHive-d80b44003ca03cd09bf28278bf2e243581c00332.zip
Fixed GetById to return only public info
Diffstat (limited to 'src/DevHive.Services')
-rw-r--r--src/DevHive.Services/Configurations/Mapping/UserMappings.cs2
-rw-r--r--src/DevHive.Services/Services/UserService.cs11
2 files changed, 6 insertions, 7 deletions
diff --git a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
index 9a35e43..ca8fa20 100644
--- a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
+++ b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
@@ -11,6 +11,8 @@ namespace DevHive.Services.Configurations.Mapping
CreateMap<UserServiceModel, User>();
CreateMap<RegisterServiceModel, User>();
CreateMap<UpdateUserServiceModel, User>();
+
+ CreateMap<User, UserServiceModel>();
}
}
}
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index c71209e..06f8b1b 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -11,7 +11,6 @@ using System.Security.Claims;
using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography;
using System.Text;
-using System.Collections.Immutable;
namespace DevHive.Services.Services
{
@@ -62,14 +61,12 @@ namespace DevHive.Services.Services
return new CreatedResult("CreateUser", user);
}
- public async Task<IActionResult> GetUserById(Guid id)
+ public async Task<UserServiceModel> GetUserById(Guid id)
{
- User user = await this._userRepository.GetByIdAsync(id);
-
- if (user == null)
- return new NotFoundObjectResult("User does not exist!");
+ User user = await this._userRepository.GetByIdAsync(id)
+ ?? throw new ArgumentException("User does not exist!");
- return new OkObjectResult(user);
+ return this._userMapper.Map<UserServiceModel>(user);
}
public async Task<IActionResult> UpdateUser(UpdateUserServiceModel updateModel)