public async Task <List <Profile> > Handle(Query request, CancellationToken cancellationToken) { var queryable = _context.Followings.AsQueryable(); var userFollowings = new List <UserFollowing>(); var profiles = new List <Profile>(); switch (request.Predicate) { case "followers": { userFollowings = await queryable .Where(x => x.Target.UserName == request.Username).ToListAsync(); foreach (var follower in userFollowings) { profiles.Add(await _profileReader.ReadProfie(follower.Observer.UserName)); } break; } case "following": { userFollowings = await queryable .Where(x => x.Observer.UserName == request.Username).ToListAsync(); foreach (var follower in userFollowings) { profiles.Add(await _profileReader.ReadProfie(follower.Target.UserName)); } break; } } return(profiles); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { return(await _profileReader.ReadProfie(request.Username)); }