aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-28 22:40:15 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-28 22:40:15 +0200
commitb8e7ec5c7925b0f62e9dc6efba28f1271f912801 (patch)
tree50e94cb31f3671cd8f1aee641498a6022ee7f7ce
parent9ceef59cb170640cb7cff643de7efd19ad8a48e9 (diff)
downloadDevHive-b8e7ec5c7925b0f62e9dc6efba28f1271f912801.tar
DevHive-b8e7ec5c7925b0f62e9dc6efba28f1271f912801.tar.gz
DevHive-b8e7ec5c7925b0f62e9dc6efba28f1271f912801.zip
Fixed the return type of UserService.DeleteUser and refactored UserController.Delete to return BadRequestObjectResult if user is not deleted successfully
-rw-r--r--src/DevHive.Services/Interfaces/IUserService.cs2
-rw-r--r--src/DevHive.Services/Services/UserService.cs5
-rw-r--r--src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs4
-rw-r--r--src/DevHive.Web/Controllers/UserController.cs5
4 files changed, 9 insertions, 7 deletions
diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs
index 9372517..700010c 100644
--- a/src/DevHive.Services/Interfaces/IUserService.cs
+++ b/src/DevHive.Services/Interfaces/IUserService.cs
@@ -15,7 +15,7 @@ namespace DevHive.Services.Interfaces
Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel);
- Task DeleteUser(Guid id);
+ Task<bool> DeleteUser(Guid id);
Task<bool> ValidJWT(Guid id, string rawTokenData);
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index f8fe2ed..ec74b5f 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -120,7 +120,7 @@ namespace DevHive.Services.Services
#endregion
#region Delete
- public async Task DeleteUser(Guid id)
+ public async Task<bool> DeleteUser(Guid id)
{
if (!await this._userRepository.DoesUserExistAsync(id))
throw new ArgumentException("User does not exist!");
@@ -128,8 +128,7 @@ namespace DevHive.Services.Services
User user = await this._userRepository.GetByIdAsync(id);
bool result = await this._userRepository.DeleteAsync(user);
- if (!result)
- throw new InvalidOperationException("Unable to delete user!");
+ return result;
}
#endregion
diff --git a/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs
index 32f2c56..1abc0f1 100644
--- a/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Services.Tests/UserService.Tests.cs
@@ -333,9 +333,9 @@ namespace DevHive.Services.Tests
this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(user));
this.UserRepositoryMock.Setup(p => p.DeleteAsync(It.IsAny<User>())).Returns(Task.FromResult(shouldPass));
- //bool result = await this.UserService.DeleteUser(id);
+ bool result = await this.UserService.DeleteUser(id);
- Assert.Pass();
+ Assert.AreEqual(shouldPass, result);
}
[Test]
diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs
index e409eea..f9fb083 100644
--- a/src/DevHive.Web/Controllers/UserController.cs
+++ b/src/DevHive.Web/Controllers/UserController.cs
@@ -100,7 +100,10 @@ namespace DevHive.Web.Controllers
if (!await this._userService.ValidJWT(id, authorization))
return new UnauthorizedResult();
- await this._userService.DeleteUser(id);
+ bool result = await this._userService.DeleteUser(id);
+ if (!result)
+ return new BadRequestObjectResult("Could not delete User");
+
return new OkResult();
}
#endregion