Exemple #1
0
        public async Task <Unit> Handle(GenerateFeedCommand request, CancellationToken cancellationToken)
        {
            var member = await _memberRepository.GetByIdAsync(new MemberId(Guid.Parse(request.MemberId)))
                         ?? throw new MemberNotFoundException($"Member with id: {request.MemberId} is not found");

            var bets = await _betRepository.GetBetsForFeedAsync();

            var feedDto = new FeedDto(member.Id.ToString(), bets.Select(x => new BetDto(x.State)));
            await _feedRepository.SaveAsync(feedDto);

            return(Unit.Value);
        }
        public async Task Handle(InsertBetQuerySideNotification notification, CancellationToken cancellationToken)
        {
            var bet = await _betRepository.GetByIdAsync(new BetId(notification.BetId))
                      ?? throw new BetUnknownException($"Bet with Id {notification.BetId} does not exists");

            var member = await _memberRepository.GetByIdAsync(new MemberId(notification.MemberId));

            var feeds = await _feedRepository.GetByIdsAsync(member.Subscriptions.Select(x => x.MemberId.Value));

            foreach (var feed in feeds)
            {
                feed.Bets.Add(new Models.BetDto(bet.State));
            }
            await _feedRepository.SaveAsync(feeds);
        }