diff options
| author | transtrike <transtrike@gmail.com> | 2021-03-15 09:27:12 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-03-15 09:27:12 +0200 |
| commit | 0161be09312fde634865f110504884119a617d5c (patch) | |
| tree | 0fa68366edcb024c054f370ecf90f5b66282aae5 /src/Web/DevHive.Web/Controllers/UserController.cs | |
| parent | e3b5757b5a5db2f7874b0924cdd4a22b1a9e1ee2 (diff) | |
| parent | ac82c773a5ec43c6a59d3d0b7665b67ac9e6bdde (diff) | |
| download | DevHive-0161be09312fde634865f110504884119a617d5c.tar DevHive-0161be09312fde634865f110504884119a617d5c.tar.gz DevHive-0161be09312fde634865f110504884119a617d5c.zip | |
Fixed to new() where possible and readable
Diffstat (limited to 'src/Web/DevHive.Web/Controllers/UserController.cs')
| -rw-r--r-- | src/Web/DevHive.Web/Controllers/UserController.cs | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/Web/DevHive.Web/Controllers/UserController.cs b/src/Web/DevHive.Web/Controllers/UserController.cs index b01ecc1..4d01447 100644 --- a/src/Web/DevHive.Web/Controllers/UserController.cs +++ b/src/Web/DevHive.Web/Controllers/UserController.cs @@ -8,12 +8,16 @@ using Microsoft.AspNetCore.Mvc; using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; using DevHive.Common.Jwt.Interfaces; -using DevHive.Web.Models.Attributes; +using NSwag.Annotations; namespace DevHive.Web.Controllers { + /// <summary> + /// All endpoints for integration with the User + /// </summary> [ApiController] [Route("/api/[controller]")] + [OpenApiController("User Controller")] public class UserController : ControllerBase { private readonly IUserService _userService; @@ -28,9 +32,15 @@ namespace DevHive.Web.Controllers } #region Authentication + /// <summary> + /// Login endpoint for the DevHive Social Platform + /// </summary> + /// <param name="loginModel">Login model with username and password</param> + /// <returns>A JWT Token for further validation</returns> [HttpPost] - [Route("Login")] [AllowAnonymous] + [Route("Login")] + [OpenApiTags("Authorization")] public async Task<IActionResult> Login([FromBody] LoginWebModel loginModel) { LoginServiceModel loginServiceModel = this._userMapper.Map<LoginServiceModel>(loginModel); @@ -41,9 +51,15 @@ namespace DevHive.Web.Controllers return new OkObjectResult(tokenWebModel); } + /// <summary> + /// Register a new User in the DevHive Social Platform + /// </summary> + /// <param name="registerModel">Register model with the new data to provide</param> + /// <returns>A JWT Token for further validation</returns> [HttpPost] - [Route("Register")] [AllowAnonymous] + [Route("Register")] + [OpenApiTag("Authorization")] public async Task<IActionResult> Register([FromBody] RegisterWebModel registerModel) { RegisterServiceModel registerServiceModel = this._userMapper.Map<RegisterServiceModel>(registerModel); @@ -56,6 +72,12 @@ namespace DevHive.Web.Controllers #endregion #region Read + /// <summary> + /// Get a User's information using the Guid + /// </summary> + /// <param name="id">User's Id</param> + /// <param name="authorization">The JWT Token, contained in the header and used for validation</param> + /// <returns>A full User's read model</returns> [HttpGet] [Authorize(Roles = "User,Admin")] public async Task<IActionResult> GetById(Guid id, [FromHeader] string authorization) @@ -69,6 +91,11 @@ namespace DevHive.Web.Controllers return new OkObjectResult(userWebModel); } + /// <summary> + /// Get a User's profile using his username. Does NOT require authorization + /// </summary> + /// <param name="username">User's username</param> + /// <returns>A trimmed version of the full User's read model</returns> [HttpGet] [Route("GetUser")] [AllowAnonymous] @@ -82,6 +109,13 @@ namespace DevHive.Web.Controllers #endregion #region Update + /// <summary> + /// Full update on User's data. A PUSTINQK can only edit his account + /// </summary> + /// <param name="id">The User's Id</param> + /// <param name="updateUserWebModel">A full User update model</param> + /// <param name="authorization">The JWT Token, contained in the header and used for validation</param> + /// <returns>A full User's read model</returns> [HttpPut] [Authorize(Roles = "User,Admin")] public async Task<IActionResult> Update(Guid id, [FromBody] UpdateUserWebModel updateUserWebModel, [FromHeader] string authorization) @@ -100,6 +134,12 @@ namespace DevHive.Web.Controllers #endregion #region Delete + /// <summary> + /// Delete a User with his Id. A PUSTINQK can only delete his account. An Admin can delete all accounts + /// </summary> + /// <param name="id">The User's Id</param> + /// <param name="authorization">The JWT Token, contained in the header and used for validation</param> + /// <returns>Ok, BadRequest or Unauthorized</returns> [HttpDelete] [Authorize(Roles = "User,Admin")] public async Task<IActionResult> Delete(Guid id, [FromHeader] string authorization) @@ -115,7 +155,13 @@ namespace DevHive.Web.Controllers } #endregion + /// <summary> + /// We don't talk about that, NIGGA! + /// </summary> + /// <param name="userId"></param> + /// <returns></returns> [HttpPost] + [OpenApiIgnore] [Authorize(Roles = "User,Admin")] [Route("SuperSecretPromotionToAdmin")] public async Task<IActionResult> SuperSecretPromotionToAdmin(Guid userId) |
