Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GET /users/me #212

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading