namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
public class GetUserRoleQueryHandler : IRequestHandler<GetUserRoleQuery, GetUserRoleResponseDto>
{
    private readonly IApplicationDbContext _context;

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

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

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