Refactoring (Controller): Aktualisierung zur Verwendung der aktuellen Version von TryGetUserId

This commit is contained in:
2025-07-25 10:44:12 +02:00
parent bed5fae01c
commit ad1fd3163e
4 changed files with 20 additions and 55 deletions

View File

@@ -26,24 +26,19 @@ public class UserController : ControllerBase
{
try
{
if (!this.TryGetUserId(out int? id))
if (!User.TryGetUserId(out var id))
{
logger.LogError("Authorization failed: User ID claim not found.");
return StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve user identity.");
}
else if(id is int id_int)
return await userService.ReadByIdAsync(id_int).ThenAsync(
Success: Ok,
Fail: IActionResult (msg, ntc) =>
{
logger.LogNotice(ntc);
return NotFound();
});
else
{
logger.LogError("Invalid user ID: Retrieved ID is null or not an integer.");
return StatusCode(StatusCodes.Status500InternalServerError, "Invalid user ID.");
return Unauthorized("Failed to retrieve user identity.");
}
return await userService.ReadByIdAsync(id).ThenAsync(
Success: Ok,
Fail: IActionResult (msg, ntc) =>
{
logger.LogNotice(ntc);
return NotFound();
});
}
catch (Exception ex)
{