- 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
56 lines
2.4 KiB
C#
56 lines
2.4 KiB
C#
using DigitalData.Core.API;
|
|
using DigitalData.Core.DTO;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using WorkFlow.Application.Contracts;
|
|
using WorkFlow.Application.DTO.ProfileControlsTF;
|
|
using WorkFlow.Domain.Entities;
|
|
|
|
namespace WorkFlow.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class ProfileControlsTFController(ILogger<ProfileControlsTFController> logger, IProfileControlsTFService service) : CRUDControllerBaseWithErrorHandling<IProfileControlsTFService, ProfileControlsTFCreateDto, ProfileControlsTFDto, ProfileControlsTFUpdateDto, ProfileControlsTF, int>(logger, service)
|
|
{
|
|
[NonAction]
|
|
public override Task<IActionResult> GetAll() => base.GetAll();
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAsync(
|
|
bool withProfile = true, bool withUser = false,
|
|
int? profileId = null, int? objId = null, bool? profileActive = null)
|
|
{
|
|
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 null)
|
|
{
|
|
logger.LogError("Invalid user ID: Retrieved ID is null or not an integer.");
|
|
return StatusCode(StatusCodes.Status500InternalServerError, "Invalid user ID.");
|
|
}
|
|
|
|
return await _service.ReadAsync(
|
|
withProfile: withProfile, withUser: withUser,
|
|
userId: id,
|
|
profileId: profileId, objId: objId, profileActive: profileActive)
|
|
.ThenAsync(
|
|
Success: pctf => pctf.Any() ? Ok(pctf) : NotFound(),
|
|
Fail: IActionResult (msg, ntc) =>
|
|
{
|
|
logger.LogNotice(ntc);
|
|
return NotFound();
|
|
});
|
|
}
|
|
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.");
|
|
}
|
|
}
|
|
}
|
|
} |