- Neue GetAsync-Methode hinzugefügt, um komplexe Filter mit optionalen Parametern zu unterstützen - Verbesserte Fehlerprotokollierung und Validierung für die Extraktion der Benutzeridentität - Benutzer-ID in den Service-Schichtenoperationen integriert - Basismethode GetAll entfernt, um eine bessere Kontrolle über das Datenabrufen zu gewährleisten
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using DigitalData.Core.DTO;
|
|
using DigitalData.UserManager.Application.Contracts;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace WorkFlow.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class UserController(ILogger<UserController> logger, IUserService userService) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAsync()
|
|
{
|
|
try
|
|
{
|
|
if (!this.TryGetUserId(out int? 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.");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
|
|
}
|
|
}
|
|
}
|
|
} |