diff options
author | crupest <crupest@outlook.com> | 2020-11-15 20:48:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-11-15 20:48:28 +0800 |
commit | 1bbc60966cea77ec6ed7895bea1a01ad9c090c3a (patch) | |
tree | 7c2c792c141def97603cb43d98e83d29ac718e9a /BackEnd/Timeline/Services/UserDeleteService.cs | |
parent | 667143d870679deb4be55122237e66d2d480946f (diff) | |
download | timeline-1bbc60966cea77ec6ed7895bea1a01ad9c090c3a.tar.gz timeline-1bbc60966cea77ec6ed7895bea1a01ad9c090c3a.tar.bz2 timeline-1bbc60966cea77ec6ed7895bea1a01ad9c090c3a.zip |
feat: Deleting root user now returns 400.
Diffstat (limited to 'BackEnd/Timeline/Services/UserDeleteService.cs')
-rw-r--r-- | BackEnd/Timeline/Services/UserDeleteService.cs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/UserDeleteService.cs b/BackEnd/Timeline/Services/UserDeleteService.cs index b6306682..5365313b 100644 --- a/BackEnd/Timeline/Services/UserDeleteService.cs +++ b/BackEnd/Timeline/Services/UserDeleteService.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Timeline.Entities;
using Timeline.Helpers;
using Timeline.Models.Validation;
+using Timeline.Services.Exceptions;
using static Timeline.Resources.Services.UserService;
namespace Timeline.Services
@@ -20,6 +21,7 @@ namespace Timeline.Services /// <returns>True if user is deleted, false if user not exist.</returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="username"/> is null.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="username"/> is of bad format.</exception>
+ /// <exception cref="InvalidOperationOnRootUserException">Thrown when deleting root user.</exception>
Task<bool> DeleteUser(string username);
}
@@ -54,6 +56,9 @@ namespace Timeline.Services if (user == null)
return false;
+ if (user.Id == 1)
+ throw new InvalidOperationOnRootUserException("Can't delete root user.");
+
await _timelineService.DeleteAllPostsOfUser(user.Id);
_databaseContext.Users.Remove(user);
|