コード例 #1
0
        public async Task <CountTeamStubsProjection> HandleAsync(CountTeamStubsQuery query,
                                                                 CancellationToken cancellationToken)
        {
            if (_authenticatedUserAccessor.AuthenticatedUser.Teams.All(t => t.Id != query.TeamId))
            {
                throw new UserNotAddedToTeamException
                      (
                          _authenticatedUserAccessor.AuthenticatedUser.Id,
                          query.TeamId
                      );
            }

            var tags = await _cache.GetOrSetAsync
                       (
                _cacheKey.CountTeamInvitations(query.TeamId),
                async() => await _stubsCollection.Find(s => s.TeamId == query.TeamId)
                .Project(s => s.Tags)
                .ToListAsync()
                       );

            var tagCounts = tags.SelectMany(t => t)
                            .GroupBy(g => g)
                            .Select(g => new TagCount
                                    (
                                        g.Key,
                                        g.Count()
                                    ))
                            .ToList();

            return(new CountTeamStubsProjection
                   (
                       tags.Count,
                       tagCounts
                   ));
        }
コード例 #2
0
        public Task HandleAsync(TeamInvitationCreatedEvent @event, CancellationToken cancellationToken)
        {
            _cache.Remove(_cacheKey.CountTeamInvitations
                          (
                              @event.TeamId
                          ));

            return(Task.CompletedTask);
        }
コード例 #3
0
        public async Task <CountTeamInvitationsProjection> HandleAsync(CountTeamInvitationsQuery query,
                                                                       CancellationToken cancellationToken)
        {
            if (_authenticatedUserAccessor.AuthenticatedUser.Teams.All(t => t.Id != query.TeamId))
            {
                throw new UserNotAddedToTeamException
                      (
                          _authenticatedUserAccessor.AuthenticatedUser.Id,
                          query.TeamId
                      );
            }

            var totalCount = await _cache.GetOrSetAsync
                             (
                _cacheKey.CountTeamInvitations(query.TeamId),
                async() => await _invitationsCollection.CountAsync(i => i.Team.Id == query.TeamId)
                             );

            return(new CountTeamInvitationsProjection
                   (
                       totalCount
                   ));
        }