Esempio n. 1
0
        public Task GetTransactions(MessageContext context, GetTransactionsEvent inputEvent)
        {
            var filters = new FilterTransactionsEvent {
                Senders = inputEvent.Ids
            };

            publishingRouter.Publish(Queues.Transactions, filters, context.FlowId, context.ReplyTo);
            return(Task.CompletedTask);
        }
        public Task GetTransactions(MessageContext context, GetTransactionsEvent inputEvent)
        {
            var paymentsIds          = inputEvent.Ids != null && inputEvent.Ids.Length > 0 ? inputEvent.Ids : paymentsRepository.GetIds();
            var getTransactionsEvent = new FilterTransactionsEvent {
                Payments = paymentsIds, TimestampFrom = inputEvent.TimestampFrom, TimestampTo = inputEvent.TimestampTo
            };

            publishingRouter.Publish(Queues.Transactions, getTransactionsEvent, context.FlowId, context.ReplyTo);
            return(Task.CompletedTask);
        }
Esempio n. 3
0
        public Task Filter(MessageContext context, FilterTransactionsEvent inputEvent)
        {
            var filters = new Filters
            {
                Cards         = inputEvent.Cards?.ToHashSet(),
                Payments      = inputEvent.Payments?.ToHashSet(),
                Recipients    = inputEvent.Recipients?.ToHashSet(),
                Senders       = inputEvent.Senders?.ToHashSet(),
                TimestampFrom = inputEvent.TimestampFrom,
                TimestampTo   = inputEvent.TimestampTo,
            };

            var transactions = transactionsRepository.GetMany(filters, inputEvent.Top);

            publishingRouter.Publish(context.ReplyTo, new SelectedTransactionsEvent {
                Transactions = transactions
            }, context.FlowId);
            return(Task.CompletedTask);
        }
        public async Task <Panel> Panel(string userId)
        {
            var mainFlowId = HttpContext.Items["flowId"].ToString();

            var panel = new Panel {
                Accounts = new AccountDTO[0], Cards = new CardDTO[0], Payments = new PaymentDTO[0], Transactions = new TransactionDTO[0], Loans = new LoanDTO[0]
            };

            var accountsFlowId = mainFlowId + "_a";
            var accountsEvent  = new GetUserAccountsEvent {
                UserId = userId
            };
            var accountsResponse = await eventsAwaiter.AwaitResponse <SelectedAccountsEvent>(accountsFlowId, () => publishingRouter.Publish(Queues.Accounts, accountsEvent, accountsFlowId, Queues.APIGateway));

            panel.Accounts = mapper.Map <AccountDTO[]>(accountsResponse.Accounts);
            var accountsIds = accountsResponse.Accounts.Select(a => a.Id).ToArray();

            if (accountsIds.Any())
            {
                var parallelTasks = new List <Task>();
                parallelTasks.Add(Task.Run(async() =>
                {
                    var transactionsFlowId = mainFlowId + "_t";
                    var transactionsEvent  = new FilterTransactionsEvent {
                        Senders = accountsIds, Top = PanelTransactionsCount
                    };
                    var transactionsResponse = await eventsAwaiter.AwaitResponse <SelectedTransactionsEvent>(transactionsFlowId, () => publishingRouter.Publish(Queues.Transactions, transactionsEvent, transactionsFlowId, Queues.APIGateway));
                    panel.Transactions       = mapper.Map <TransactionDTO[]>(transactionsResponse.Transactions);
                }));

                parallelTasks.Add(Task.Run(async() =>
                {
                    var paymentsFlowId = mainFlowId + "_p";
                    var paymentsEvent  = new GetPaymentsByAccountsEvent {
                        AccountsIds = accountsIds
                    };
                    var paymentsResponse = await eventsAwaiter.AwaitResponse <SelectedPaymentsEvent>(paymentsFlowId, () => publishingRouter.Publish(Queues.Payments, paymentsEvent, paymentsFlowId, Queues.APIGateway));
                    panel.Payments       = mapper.Map <PaymentDTO[]>(paymentsResponse.Payments);

                    var loansFlowId = mainFlowId + "_l";
                    var paymentsIds = paymentsResponse.Payments.Select(p => p.Id).ToArray();
                    var loansEvent  = new GetLoansByPaymentsEvent {
                        PaymentsIds = paymentsIds
                    };
                    var loansResponse = await eventsAwaiter.AwaitResponse <SelectedLoansEvent>(loansFlowId, () => publishingRouter.Publish(Queues.Loans, loansEvent, loansFlowId, Queues.APIGateway));
                    panel.Loans       = mapper.Map <LoanDTO[]>(loansResponse.Loans);
                }));

                parallelTasks.Add(Task.Run(async() =>
                {
                    var cardsFlowId = mainFlowId + "_c";
                    var cardsEvent  = new GetCardsByAccountsEvent {
                        AccountsIds = accountsIds
                    };
                    var cardsResponse = await eventsAwaiter.AwaitResponse <SelectedCardsEvent>(cardsFlowId, () => publishingRouter.Publish(Queues.Cards, cardsEvent, cardsFlowId, Queues.APIGateway));
                    panel.Cards       = mapper.Map <CardDTO[]>(cardsResponse.Cards);
                }));

                await Task.WhenAll(parallelTasks);
            }

            return(panel);
        }