public async Task <Account[]> GetAccounts(string flowId, string userId)
        {
            var payload = new GetUserAccountsEvent {
                UserId = userId
            };
            var response = await eventsAwaiter.AwaitResponse <SelectedAccountsEvent>(flowId, () => publishingRouter.Publish(Queues.Accounts, payload, flowId, Queues.Transactions));

            return(response.Accounts);
        }
        public async Task <IEnumerable <AccountDTO> > Get(string userId)
        {
            var flowId  = HttpContext.Items["flowId"].ToString();
            var payload = new GetUserAccountsEvent {
                UserId = userId
            };
            var response = await eventsAwaiter.AwaitResponse <SelectedAccountsEvent>(flowId, () => publishingRouter.Publish(Queues.Accounts, payload, flowId, Queues.APIGateway));

            var accounts = response.Accounts.Select(a => mapper.Map <AccountDTO>(a));

            return(accounts);
        }
        public async Task <string> UserActivity(UserActivityReportRequest data)
        {
            var payload = new AggregateUserActivityReportDataEvent
            {
                Granularity   = data.Granularity,
                TimestampFrom = data.TimestampFrom,
                TimestampTo   = data.TimestampTo,
                UserId        = data.UserId,
            };
            var flowId   = HttpContext.Items["flowId"].ToString();
            var response = await eventsAwaiter.AwaitResponse <AggregatedUserActivityReportEvent>(flowId, () => publishingRouter.Publish(Queues.Transactions, payload, flowId, Queues.APIGateway));

            return(ReportCsvSerializer.SerializerUserActivityReport(data.UserId, data.TimestampFrom, data.TimestampTo, data.Granularity, response));
        }
コード例 #4
0
        public async Task <BatchData> Get([FromQuery(Name = "part")] int part, [FromQuery(Name = "total")] int total, [FromQuery(Name = "timestamp")] DateTime timestamp)
        {
            var flowId = HttpContext.Items["flowId"].ToString();

            Payment[]        payments = null;
            Loan[]           loans    = null;
            AccountBalance[] balances = null;

            var paymentsFlowId = flowId + "_p";
            var paymentsEvent  = new GetPartPaymentsEvent {
                Part = part, TotalParts = total, Timestamp = timestamp
            };
            var paymentsResponse = await eventsAwaiter.AwaitResponse <SelectedPaymentsEvent>(paymentsFlowId, () => publishingRouter.Publish(Queues.Payments, paymentsEvent, paymentsFlowId, Queues.APIGateway));

            payments = paymentsResponse.Payments;

            var parallelTasks = new List <Task>();

            parallelTasks.Add(Task.Run(async() =>
            {
                var loansFlowId = flowId + "_l";
                var paymentsIds = 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));
                loans             = loansResponse.Loans;
            }));
            parallelTasks.Add(Task.Run(async() =>
            {
                var balancesFlowId = flowId + "_b";
                var accountsIds    = payments.Select(p => p.AccountId).Distinct().ToArray();
                var balancesEvent  = new GetBalancesEvent {
                    Ids = accountsIds
                };
                var balancesRequest = await eventsAwaiter.AwaitResponse <SelectedBalancesEvent>(balancesFlowId, () => publishingRouter.Publish(Queues.Accounts, balancesEvent, balancesFlowId, Queues.APIGateway));
                balances            = balancesRequest.Balances;
            }));

            await Task.WhenAll(parallelTasks);

            return(new BatchData
            {
                Balances = balances.Select(b => mapper.Map <BalanceDTO>(b)).ToArray(),
                Loans = loans.Select(l => mapper.Map <LoanDTO>(l)).ToArray(),
                Payments = payments.Select(p => mapper.Map <PaymentDTO>(p)).ToArray()
            });
        }
コード例 #5
0
        public async Task Transfer(MessageContext context, TransferEvent inputEvent)
        {
            var card = cardsRepository.GetCard(inputEvent.Transfer.CardId);

            if (card == null)
            {
                throw new ArgumentException("Card not found.");
            }

            var blockRequestTime = DateTime.UtcNow;
            var title            = $"{DateTime.UtcNow} card usage for a transfer worth {inputEvent.Transfer.Amount} EUR";

            var transfer = new Transfer
            {
                AccountId = card.AccountId,
                CardId    = card.Id,
                Recipient = inputEvent.Transfer.Recipient,
                Amount    = inputEvent.Transfer.Amount,
                Title     = title
            };

            var accountTransferEvent = new TransferEvent {
                Transfer = transfer
            };
            var reply = await eventsAwaiter.AwaitResponse <SelectedTransactionsEvent>(context.FlowId, () => publishingRouter.Publish(Queues.Accounts, accountTransferEvent, context.FlowId, Queues.Cards));

            var transaction = reply.Transactions.Single();

            cardsRepository.CreateBlock(card.Id, transaction.Id, blockRequestTime);
            if (context.ReplyTo != null)
            {
                publishingRouter.Publish(context.ReplyTo, reply, context.FlowId);
            }
        }
        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);
        }