From bcdb0e737710052018d781b8ffd197bd11644553 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 12 Apr 2022 18:30:08 +0800 Subject: ... --- .../Controllers/V2/TimelinePostV2Controller.cs | 6 +++--- .../Timeline/Controllers/V2/TimelineV2Controller.cs | 4 ++-- BackEnd/Timeline/Controllers/V2/UserV2Controller.cs | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'BackEnd/Timeline/Controllers') diff --git a/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs b/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs index aa839abf..8a4fa7ed 100644 --- a/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs +++ b/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs @@ -144,7 +144,7 @@ namespace Timeline.Controllers.V2 var data = body.DataList[i]; if (data is null) - return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Data at index {i} is null.")); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, $"Data at index {i} is null.")); try { @@ -153,7 +153,7 @@ namespace Timeline.Controllers.V2 } catch (FormatException) { - return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Data at index {i} is not a valid base64 string.")); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, $"Data at index {i} is not a valid base64 string.")); } } @@ -169,7 +169,7 @@ namespace Timeline.Controllers.V2 } catch (TimelinePostCreateDataException e) { - return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Data at index {e.Index} is invalid. {e.Message}")); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, $"Data at index {e.Index} is invalid. {e.Message}")); } } diff --git a/BackEnd/Timeline/Controllers/V2/TimelineV2Controller.cs b/BackEnd/Timeline/Controllers/V2/TimelineV2Controller.cs index 393446f7..7f620928 100644 --- a/BackEnd/Timeline/Controllers/V2/TimelineV2Controller.cs +++ b/BackEnd/Timeline/Controllers/V2/TimelineV2Controller.cs @@ -99,7 +99,7 @@ namespace Timeline.Controllers.V2 } catch (EntityNotExistException e) when (e.EntityType.Equals(EntityTypes.User)) { - return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, "Member username does not exist.")); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, "Member username does not exist.")); } await _timelineService.AddMemberAsync(timelineId, userId); return NoContent(); @@ -127,7 +127,7 @@ namespace Timeline.Controllers.V2 } catch (EntityNotExistException e) when (e.EntityType.Equals(EntityTypes.User)) { - return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, "Member username does not exist.")); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, "Member username does not exist.")); } await _timelineService.RemoveMemberAsync(timelineId, userId); return NoContent(); diff --git a/BackEnd/Timeline/Controllers/V2/UserV2Controller.cs b/BackEnd/Timeline/Controllers/V2/UserV2Controller.cs index e556bf8e..2eb67d72 100644 --- a/BackEnd/Timeline/Controllers/V2/UserV2Controller.cs +++ b/BackEnd/Timeline/Controllers/V2/UserV2Controller.cs @@ -90,7 +90,7 @@ namespace Timeline.Controllers.V2 [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] - public async Task> Patch([FromBody] HttpUserPatchRequest body, [FromRoute][Username] string username) + public async Task> PatchAsync([FromBody] HttpUserPatchRequest body, [FromRoute][Username] string username) { var userId = await _userService.GetUserIdByUsernameAsync(username); if (UserHasPermission(UserPermission.UserManagement)) @@ -114,6 +114,8 @@ namespace Timeline.Controllers.V2 } } + private const string RootUserInvalidOperationMessage = "Can't do this operation on root user."; + /// /// Delete a user and all his related data. You have to be administrator. /// @@ -125,7 +127,7 @@ namespace Timeline.Controllers.V2 [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] - public async Task> Delete([FromRoute][Username] string username) + public async Task DeleteAsync([FromRoute][Username] string username) { try { @@ -134,7 +136,7 @@ namespace Timeline.Controllers.V2 } catch (InvalidOperationOnRootUserException) { - return UnprocessableEntity(); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidOperation, RootUserInvalidOperationMessage)); } } @@ -144,7 +146,7 @@ namespace Timeline.Controllers.V2 [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] - public async Task> PutUserPermission([FromRoute][Username] string username, [FromRoute] UserPermission permission) + public async Task PutUserPermissionAsync([FromRoute][Username] string username, [FromRoute] UserPermission permission) { try { @@ -154,17 +156,17 @@ namespace Timeline.Controllers.V2 } catch (InvalidOperationOnRootUserException) { - return UnprocessableEntity(); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidOperation, RootUserInvalidOperationMessage)); } } [HttpDelete("{username}/permissions/{permission}"), PermissionAuthorize(UserPermission.UserManagement)] [ProducesResponseType(StatusCodes.Status204NoContent)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] - public async Task> DeleteUserPermission([FromRoute][Username] string username, [FromRoute] UserPermission permission) + public async Task DeleteUserPermissionAsync([FromRoute][Username] string username, [FromRoute] UserPermission permission) { try { @@ -174,7 +176,7 @@ namespace Timeline.Controllers.V2 } catch (InvalidOperationOnRootUserException) { - return UnprocessableEntity(); + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidOperation, RootUserInvalidOperationMessage)); } } } -- cgit v1.2.3