From a672e10faad434899d81ef9d0d0d5adbbc7841da Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 30 Apr 2021 16:52:55 +0800 Subject: refactor: ... --- .../Timeline/Controllers/UserAvatarController.cs | 32 +++------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'BackEnd/Timeline/Controllers/UserAvatarController.cs') diff --git a/BackEnd/Timeline/Controllers/UserAvatarController.cs b/BackEnd/Timeline/Controllers/UserAvatarController.cs index b1129329..5d9becaa 100644 --- a/BackEnd/Timeline/Controllers/UserAvatarController.cs +++ b/BackEnd/Timeline/Controllers/UserAvatarController.cs @@ -44,16 +44,8 @@ namespace Timeline.Controllers public async Task Get([FromRoute][Username] string username, [FromHeader(Name = "If-None-Match")] string? ifNoneMatch) { _ = ifNoneMatch; - try - { - long userId = await _userService.GetUserIdByUsernameAsync(username); - return await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarDigestAsync(userId), () => _service.GetAvatarAsync(userId)); - } - catch (UserNotExistException) - { - return NotFound(ErrorResponse.UserCommon.NotExist()); - } - + long userId = await _userService.GetUserIdByUsernameAsync(username); + return await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarDigestAsync(userId), () => _service.GetAvatarAsync(userId)); } /// @@ -76,15 +68,7 @@ namespace Timeline.Controllers return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } - long id; - try - { - id = await _userService.GetUserIdByUsernameAsync(username); - } - catch (UserNotExistException) - { - return BadRequest(ErrorResponse.UserCommon.NotExist()); - } + long id = await _userService.GetUserIdByUsernameAsync(username); try { @@ -127,15 +111,7 @@ namespace Timeline.Controllers return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } - long id; - try - { - id = await _userService.GetUserIdByUsernameAsync(username); - } - catch (UserNotExistException) - { - return BadRequest(ErrorResponse.UserCommon.NotExist()); - } + long id = await _userService.GetUserIdByUsernameAsync(username); await _service.DeleteAvatarAsync(id); return Ok(); -- cgit v1.2.3