using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using WorkFlow.API.Attributes; using WorkFlow.Application.Profiles; namespace WorkFlow.API.Controllers; [APIKeyAuth] [Route("api/[controller]")] [ApiController] [Authorize] public class ProfileController : ControllerBase { private readonly ILogger _logger; private readonly IMediator _mediator; public ProfileController(ILogger logger, IMediator mediator) { _logger = logger; _mediator = mediator; } [HttpGet] public async Task GetAsync() { try { if (!User.TryGetUserId(out var userId)) { _logger.LogError("Invalid user ID: Retrieved ID is null or not an integer."); return Unauthorized("Failed to retrieve user identity."); } var profile = await _mediator.ReadProfileAsync(userId); return profile is null ? NotFound() : Ok(profile); } catch (Exception ex) { _logger.LogError(ex, "{Message}", ex.Message); return StatusCode(500); } } }