Добавлен CORS, исправлен профиль

This commit is contained in:
Халимов Рустам
2026-02-13 11:45:41 +03:00
parent a474313cec
commit b24b9d697f
3 changed files with 70 additions and 11 deletions

View File

@@ -0,0 +1,41 @@
using MediatR;
using Nashel.BuildingBlocks.Application.Abstractions;
using Nashel.Modules.Identity.Domain.Repositories;
namespace Nashel.Modules.Identity.Application.Queries.GetProfile;
public record GetProfileQuery : IRequest<ProfileResponse>;
public record ProfileResponse(Guid Id, string Phone, List<string> Roles);
public class GetProfileQueryHandler : IRequestHandler<GetProfileQuery, ProfileResponse>
{
private readonly IAccountRepository _accountRepository;
private readonly ICurrentUserService _currentUserService;
public GetProfileQueryHandler(IAccountRepository accountRepository, ICurrentUserService currentUserService)
{
_accountRepository = accountRepository;
_currentUserService = currentUserService;
}
public async Task<ProfileResponse> 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());
}
}