using MediatR; using Nashel.BuildingBlocks.Application.Abstractions; using Nashel.Modules.Identity.Domain.Repositories; namespace Nashel.Modules.Identity.Application.Queries.GetProfile; public record GetProfileQuery : IRequest; public record ProfileResponse(Guid Id, string Phone, List Roles); public class GetProfileQueryHandler : IRequestHandler { private readonly IAccountRepository _accountRepository; private readonly ICurrentUserService _currentUserService; public GetProfileQueryHandler(IAccountRepository accountRepository, ICurrentUserService currentUserService) { _accountRepository = accountRepository; _currentUserService = currentUserService; } public async Task Handle(GetProfileQuery request, CancellationToken cancellationToken) { var userId = _currentUserService.UserId; if (userId == null) { throw new UnauthorizedAccessException(); } var account = await _accountRepository.GetByIdAsync(userId.Value, cancellationToken); if (account == null) { throw new Exception("Account not found"); } return new ProfileResponse( account.Id, account.Phone, account.Roles.Select(r => r.ToString()).ToList()); } }