From e536121d97610af09d6bf4a51a875b0f7d50f702 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 30 Apr 2021 17:53:40 +0800 Subject: refactor: ... --- BackEnd/Timeline/Controllers/UserController.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'BackEnd/Timeline/Controllers/UserController.cs') diff --git a/BackEnd/Timeline/Controllers/UserController.cs b/BackEnd/Timeline/Controllers/UserController.cs index bdf9c0b7..ec732caa 100644 --- a/BackEnd/Timeline/Controllers/UserController.cs +++ b/BackEnd/Timeline/Controllers/UserController.cs @@ -102,16 +102,13 @@ namespace Timeline.Controllers else { if (User.Identity!.Name != username) - return StatusCode(StatusCodes.Status403Forbidden, - ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.Common_Forbid_NotSelf)); + return this.ForbidWithMessage(Resource.MessageForbidNotAdministratorOrOwner); if (body.Username != null) - return StatusCode(StatusCodes.Status403Forbidden, - ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.UserController_Patch_Forbid_Username)); + return this.ForbidWithMessage(Resource.MessageForbidNotAdministrator); if (body.Password != null) - return StatusCode(StatusCodes.Status403Forbidden, - ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.UserController_Patch_Forbid_Password)); + return this.ForbidWithMessage(Resource.MessageForbidNotAdministrator); var user = await _userService.ModifyUserAsync(this.GetUserId(), _mapper.AutoMapperMap(body)); return await _mapper.MapAsync(user, Url, User); @@ -140,7 +137,7 @@ namespace Timeline.Controllers } catch (InvalidOperationOnRootUserException) { - return BadRequest(ErrorResponse.UserController.Delete_RootUser()); + return this.BadRequestWithCommonResponse(ErrorCodes.UserController.InvalidOperationOnRootUser, Resource.MessageInvalidOperationOnRootUser); } } @@ -160,7 +157,7 @@ namespace Timeline.Controllers } catch (BadPasswordException) { - return BadRequest(ErrorResponse.UserController.ChangePassword_BadOldPassword()); + return this.BadRequestWithCommonResponse(ErrorCodes.UserController.ChangePasswordBadOldPassword, Resource.MessageOldPasswordWrong); } // User can't be non-existent or the token is bad. } @@ -181,7 +178,7 @@ namespace Timeline.Controllers } catch (InvalidOperationOnRootUserException) { - return BadRequest(ErrorResponse.UserController.ChangePermission_RootUser()); + return this.BadRequestWithCommonResponse(ErrorCodes.UserController.InvalidOperationOnRootUser, Resource.MessageInvalidOperationOnRootUser); } } @@ -201,7 +198,7 @@ namespace Timeline.Controllers } catch (InvalidOperationOnRootUserException) { - return BadRequest(ErrorResponse.UserController.ChangePermission_RootUser()); + return this.BadRequestWithCommonResponse(ErrorCodes.UserController.InvalidOperationOnRootUser, Resource.MessageInvalidOperationOnRootUser); } } } -- cgit v1.2.3