namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress;
public class GetUserAddressQueryHandler : IRequestHandler<GetUserAddressQuery, GetUserAddressResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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