public async Task <Result <IImmutableList <GroupModel> > > Handle(GetAdministeredGroups request, CancellationToken cancellationToken) { var isValid = await _validator.IsValidAsync(request); if (!isValid) { return(Result.Failure <IImmutableList <GroupModel> >("Validation failed")); } var user = await _context.Users.FirstAsync(u => u.Sub == request.UserSub, cancellationToken); var groups = await _context .Groups .Where(g => g.AdminId == user.Id) .Include(g => g.Admin) .Select(g => new GroupModel { Id = g.Id, Name = g.Name, NumberOfMembers = g.GroupMembers.Count, AdminId = g.AdminId, AdminFirstName = g.Admin.FirstName, AdminLastName = g.Admin.LastName }) .ToListAsync(cancellationToken); return(groups.ToImmutableList()); }
public async Task <ActionResult <IImmutableList <GroupModel> > > GetMyGroupsAsync() { var sub = User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value; var query = new GetAdministeredGroups(sub); var result = await _mediator.Send(query); if (result.IsFailure) { return(BadRequest()); } return(Ok(result.Value)); }