From 56ce7def278aef513204f6b4817f3de63d58cf60 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Thu, 22 Aug 2019 15:06:15 +0800 Subject: Add nickname in detail controller. --- Timeline/Controllers/UserDetailController.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'Timeline/Controllers/UserDetailController.cs') diff --git a/Timeline/Controllers/UserDetailController.cs b/Timeline/Controllers/UserDetailController.cs index 9e1d5483..5e1183c1 100644 --- a/Timeline/Controllers/UserDetailController.cs +++ b/Timeline/Controllers/UserDetailController.cs @@ -10,7 +10,7 @@ using Timeline.Services; namespace Timeline.Controllers { - [Route("users/{username}/details")] + [Route("users/{username}")] [ProducesErrorResponseType(typeof(CommonResponse))] [ApiController] public class UserDetailController : Controller @@ -22,6 +22,7 @@ namespace Timeline.Controllers public const int Patch_Forbid = -2001; public const int Patch_UserNotExist = -2002; + public const int GetNickname_UserNotExist = -3001; } private readonly ILogger _logger; @@ -33,7 +34,27 @@ namespace Timeline.Controllers _service = service; } - [HttpGet()] + [HttpGet("nickname")] + [UserAuthorize] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(UserDetail))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetNickname([FromRoute] string username) + { + try + { + var nickname = await _service.GetUserNickname(username); + return Ok(new UserDetail + { + Nickname = nickname + }); + } + catch (UserNotExistException) + { + return NotFound(new CommonResponse(ErrorCodes.GetNickname_UserNotExist, "The user does not exist.")); + } + } + + [HttpGet("details")] [UserAuthorize] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(UserDetail))] [ProducesResponseType(StatusCodes.Status404NotFound)] @@ -50,7 +71,7 @@ namespace Timeline.Controllers } } - [HttpPatch()] + [HttpPatch("details")] [Authorize] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(void))] [ProducesResponseType(StatusCodes.Status400BadRequest)] -- cgit v1.2.3