namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
public class GetUserWalletQueryHandler : IRequestHandler<GetUserWalletQuery, GetUserWalletResponseDto>
{
    private readonly IApplicationDbContext _context;

    public GetUserWalletQueryHandler(IApplicationDbContext context)
    {
        _context = context;
    }

    public async Task<GetUserWalletResponseDto> Handle(GetUserWalletQuery request,
        CancellationToken cancellationToken)
    {
        var response = await _context.UserWallets
            .AsNoTracking()
            .Where(x => x.Id == request.Id)
            .ProjectToType<GetUserWalletResponseDto>()
            .FirstOrDefaultAsync(cancellationToken);

        return response ?? throw new NotFoundException(nameof(UserWallet), request.Id);
    }
}
