diff --git a/WorkFlow.API/Controllers/ProfileControlsTFController.cs b/WorkFlow.API/Controllers/ProfileControlsTFController.cs index 6d747a4..82b63df 100644 --- a/WorkFlow.API/Controllers/ProfileControlsTFController.cs +++ b/WorkFlow.API/Controllers/ProfileControlsTFController.cs @@ -1,4 +1,5 @@ using DigitalData.Core.API; +using DigitalData.Core.DTO; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using WorkFlow.Application.Contracts; @@ -12,5 +13,44 @@ namespace WorkFlow.API.Controllers [Authorize] public class ProfileControlsTFController(ILogger logger, IProfileControlsTFService service) : CRUDControllerBaseWithErrorHandling(logger, service) { + [NonAction] + public override Task GetAll() => base.GetAll(); + + [HttpGet] + public async Task 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."); + } + } } } \ No newline at end of file diff --git a/WorkFlow.API/Controllers/UserController.cs b/WorkFlow.API/Controllers/UserController.cs index 0ea9646..e01c036 100644 --- a/WorkFlow.API/Controllers/UserController.cs +++ b/WorkFlow.API/Controllers/UserController.cs @@ -34,10 +34,10 @@ namespace WorkFlow.API.Controllers return StatusCode(StatusCodes.Status500InternalServerError, "Invalid user ID."); } } - catch(Exception ex) + catch (Exception ex) { - logger.LogError(exception: ex, "{message}", ex.Message); - return StatusCode(StatusCodes.Status500InternalServerError); + logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message); + return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred."); } } }