From 32fdf425e6b4f4edfb727fb3c0cbebe2c87fd663 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 20 Aug 2020 00:39:09 +0800 Subject: ... --- Timeline/Controllers/UserController.cs | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'Timeline/Controllers/UserController.cs') diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index 3986bb5b..fa2d37d8 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -17,7 +17,11 @@ using static Timeline.Resources.Messages; namespace Timeline.Controllers { + /// + /// Operations about users. + /// [ApiController] + [ProducesErrorResponseType(typeof(CommonResponse))] public class UserController : Controller { private readonly ILogger _logger; @@ -25,6 +29,7 @@ namespace Timeline.Controllers private readonly IUserDeleteService _userDeleteService; private readonly IMapper _mapper; + /// public UserController(ILogger logger, IUserService userService, IUserDeleteService userDeleteService, IMapper mapper) { _logger = logger; @@ -35,7 +40,12 @@ namespace Timeline.Controllers private UserInfo ConvertToUserInfo(User user) => _mapper.Map(user); + /// + /// Get all users. + /// + /// The user list. [HttpGet("users")] + [ProducesResponseType(typeof(UserInfo[]), StatusCodes.Status200OK)] public async Task> List() { var users = await _userService.GetUsers(); @@ -43,7 +53,13 @@ namespace Timeline.Controllers return Ok(result); } + /// + /// Get a user info. + /// + /// Username of the user. + /// The user info. [HttpGet("users/{username}")] + [ProducesResponseType(typeof(UserInfo), StatusCodes.Status200OK)] public async Task> Get([FromRoute][Username] string username) { try @@ -58,7 +74,20 @@ namespace Timeline.Controllers } } + /// + /// Change a user's property. You have to be administrator in some condition. + /// + /// + /// Username of the user to change. + /// Succeed to change the user and return the new user info. + /// You have not logged in. + /// You are not administrator. + /// The user to change does not exist. [HttpPatch("users/{username}"), Authorize] + [ProducesResponseType(typeof(UserInfo), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> Patch([FromBody] UserPatchRequest body, [FromRoute][Username] string username) { if (this.IsAdministrator()) @@ -101,7 +130,17 @@ namespace Timeline.Controllers } } + /// + /// Delete a user and all his related data. You have to be administrator. + /// + /// Username of the user to delete. + /// Succeeded to delete or the user does not exist. + /// You have not logged in. + /// You are not administrator. [HttpDelete("users/{username}"), AdminAuthorize] + [ProducesResponseType(typeof(CommonDeleteResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task> Delete([FromRoute][Username] string username) { var delete = await _userDeleteService.DeleteUser(username); @@ -111,7 +150,18 @@ namespace Timeline.Controllers return Ok(CommonDeleteResponse.NotExist()); } + /// + /// Create a new user. You have to be administrator. + /// + /// Succeeded to create a new user and return his user info. + /// Error code is 11020101 if a user with given username already exists. + /// You have not logged in. + /// You are not administrator. [HttpPost("userop/createuser"), AdminAuthorize] + [ProducesResponseType(typeof(UserInfo), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task> CreateUser([FromBody] CreateUserRequest body) { try @@ -125,7 +175,16 @@ namespace Timeline.Controllers } } + /// + /// Change password with old password. + /// + /// Succeeded to change password. + /// Error code is 11020201 if old password is wrong. + /// You have not logged in. [HttpPost("userop/changepassword"), Authorize] + [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] public async Task ChangePassword([FromBody] ChangePasswordRequest request) { try -- cgit v1.2.3