diff --git a/LeaderboardBackend/Controllers/UsersController.cs b/LeaderboardBackend/Controllers/UsersController.cs index 0ff2a3a9..47baa4b5 100644 --- a/LeaderboardBackend/Controllers/UsersController.cs +++ b/LeaderboardBackend/Controllers/UsersController.cs @@ -50,29 +50,19 @@ public async Task> GetUserById(Guid id) /// Example: `{ 'Authorization': 'Bearer JWT' }`. /// /// The `User` was found and returned successfully.. - /// An invalid JWT was passed in. + /// An invalid JWT was passed in. + /// The user was not found in the database. [HttpGet("me")] [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ApiConventionMethod(typeof(Conventions), nameof(Conventions.Get))] public async Task> Me() { - // FIXME: Use ApiConventionMethod here! - Ero - - string? email = _authService.GetEmailFromClaims(HttpContext.User); - - if (email is null) - { - return Forbid(); - } - - User? user = await _userService.GetUserByEmail(email); - - // FIXME: Should return NotFound()! - Ero - if (user is null) - { - return Forbid(); - } - - return Ok(UserViewModel.MapFrom(user)); + return (await _userService.GetUserFromClaims(HttpContext.User)).Match>( + user => Ok(UserViewModel.MapFrom(user)), + badCredentials => Unauthorized(), + userNotFound => NotFound() + ); } } diff --git a/LeaderboardBackend/openapi.json b/LeaderboardBackend/openapi.json index 95aa114e..5b4f9b6a 100644 --- a/LeaderboardBackend/openapi.json +++ b/LeaderboardBackend/openapi.json @@ -1047,7 +1047,7 @@ } } }, - "403": { + "401": { "description": "An invalid JWT was passed in.", "content": { "application/json": { @@ -1056,6 +1056,16 @@ } } } + }, + "404": { + "description": "The user was not found in the database.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } } } }