aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers/V2
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-12 18:30:08 +0800
committercrupest <crupest@outlook.com>2022-04-12 18:30:08 +0800
commitbcdb0e737710052018d781b8ffd197bd11644553 (patch)
treebd7685813d5bc11c0a170ee4b2db234464671556 /BackEnd/Timeline/Controllers/V2
parent20c8d376bdfb4ad1d2a52a0619307ff1a5b9f113 (diff)
downloadtimeline-bcdb0e737710052018d781b8ffd197bd11644553.tar.gz
timeline-bcdb0e737710052018d781b8ffd197bd11644553.tar.bz2
timeline-bcdb0e737710052018d781b8ffd197bd11644553.zip
...
Diffstat (limited to 'BackEnd/Timeline/Controllers/V2')
-rw-r--r--BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs6
-rw-r--r--BackEnd/Timeline/Controllers/V2/TimelineV2Controller.cs4
-rw-r--r--BackEnd/Timeline/Controllers/V2/UserV2Controller.cs18
3 files changed, 15 insertions, 13 deletions
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<ActionResult<HttpUser>> Patch([FromBody] HttpUserPatchRequest body, [FromRoute][Username] string username)
+ public async Task<ActionResult<HttpUser>> 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.";
+
/// <summary>
/// Delete a user and all his related data. You have to be administrator.
/// </summary>
@@ -125,7 +127,7 @@ namespace Timeline.Controllers.V2
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
- public async Task<ActionResult<CommonDeleteResponse>> Delete([FromRoute][Username] string username)
+ public async Task<ActionResult> 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<ActionResult<CommonResponse>> PutUserPermission([FromRoute][Username] string username, [FromRoute] UserPermission permission)
+ public async Task<ActionResult> 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<ActionResult<CommonResponse>> DeleteUserPermission([FromRoute][Username] string username, [FromRoute] UserPermission permission)
+ public async Task<ActionResult> 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));
}
}
}