Skip to content

Commit

Permalink
Update GET /users/me to fix issues. (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTedder authored Jun 24, 2024
1 parent 2478e84 commit 15f5a9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
30 changes: 10 additions & 20 deletions LeaderboardBackend/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,19 @@ public async Task<ActionResult<UserViewModel>> GetUserById(Guid id)
/// Example: `{ 'Authorization': 'Bearer JWT' }`.
/// </remarks>
/// <response code="200">The `User` was found and returned successfully..</response>
/// <response code="403">An invalid JWT was passed in.</response>
/// <response code="401">An invalid JWT was passed in.</response>
/// <response code="404">The user was not found in the database.</response>
[HttpGet("me")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ApiConventionMethod(typeof(Conventions), nameof(Conventions.Get))]
public async Task<ActionResult<UserViewModel>> 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<ActionResult<UserViewModel>>(
user => Ok(UserViewModel.MapFrom(user)),
badCredentials => Unauthorized(),
userNotFound => NotFound()
);
}
}
12 changes: 11 additions & 1 deletion LeaderboardBackend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@
}
}
},
"403": {
"401": {
"description": "An invalid JWT was passed in.",
"content": {
"application/json": {
Expand All @@ -1056,6 +1056,16 @@
}
}
}
},
"404": {
"description": "The user was not found in the database.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
}
Expand Down

0 comments on commit 15f5a9e

Please sign in to comment.