コード例 #1
0
        public async Task <IActionResult> GetAsync([FromQuery] string pageToken = null)
        {
            var query  = new GetTransactionsQuery(pageToken);
            var result = await this.mediator.QueryAsync <GetTransactionsQuery, PagedResultDto <TransactionByIdDto> >(query).ConfigureAwait(false);

            return(result == null?this.NotFound() : (IActionResult)this.Ok(result));
        }
コード例 #2
0
        public async Task <ActionResult <IEnumerable <UserTransaction> > > GetTransactions()
        {
            var query  = new GetTransactionsQuery();
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
コード例 #3
0
        public ITransactionSpecification Create(GetTransactionsQuery query)
        {
            var specifications = new List <ITransactionSpecification>();

            if (query.Type.HasValue)
            {
                specifications.Add(new TransactionTypeSpec(query.Type.Value));
            }

            if (query.Categories.Any())
            {
                specifications.Add(new CategoriesSpec(query.Categories));
            }

            if (query.Subcategories.Any())
            {
                specifications.Add(new SubcategoriesSpec(query.Subcategories));
            }

            if (query.PayerPayeeIds.Any())
            {
                specifications.Add(new PayerPayeeIdsSpec(query.PayerPayeeIds));
            }

            return(new AndSpec(specifications));
        }
        public async Task <TransactionHistoryData> GetTransactions(string typeFilter, string sortFilter, string orderFilter, int itemsPerPage, int pageNumber)
        {
            var transactionData = new TransactionHistoryData
            {
                TransactionsList = new List <TransactionDto>()
            };

            var query = new GetTransactionsQuery
            {
                UserId      = userManager.GetUserId(User),
                TypeFilter  = typeFilter,
                SortFilter  = sortFilter,
                OrderFilter = orderFilter
            };

            var transactionsList = await mediator.Send(query);

            transactionData.TransactionsCount = transactionsList.Count;
            transactionsList = transactionsList.Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).ToList();

            var config = new MapperConfiguration(cfg => cfg.CreateMap <Transaction, TransactionDto>());
            var mapper = new Mapper(config);

            foreach (var transaction in transactionsList)
            {
                var t = mapper.Map <TransactionDto>(transaction);
                transactionData.TransactionsList.Add(t);
            }

            return(transactionData);
        }
コード例 #5
0
        public void EmptyValueIsPassed_ValidationFailedWithExpectedErrorIsReturned()
        {
            // arrange
            var     mockApplicationDbContext = new Mock <IApplicationDbContext>();
            Account account = new()
            {
                AccountNumber = "ABC123",
                Currency      = Currency.EUR
            };
            List <Account> accounts = new List <Account>()
            {
                account,
                new()
                {
                    AccountNumber = "DEF123"
                }
            };

            var stubAccounts = new StubListOfEntities <Account>(accounts);

            mockApplicationDbContext
            .Setup(m => m.Accounts)
            .Returns(stubAccounts);
            var sut = new GetTransactionQueryValidator(mockApplicationDbContext.Object);

            // act
            var instanceToValidate = new GetTransactionsQuery();
            var validationResult   = sut.Validate(instanceToValidate);

            // assert
            validationResult.IsValid.Should().BeFalse();
            validationResult.Errors.Any(e => e.ErrorMessage == "Account Number is required.").Should().BeTrue();
        }
コード例 #6
0
        public async Task <IActionResult> Get([FromQuery] GetTransactionsQuery queryParams
                                              )
        {
            var result = await _transactionHelperService
                         .GetTransactionsAsync(queryParams);

            return(Ok(result));
        }
コード例 #7
0
        public ActionResult Get()
        {
            // Send the query
            var query        = new GetTransactionsQuery();
            var transactions = query.Run();

            return(Ok(transactions));
        }
コード例 #8
0
        public async Task <IActionResult> GetTransactionsById(int transactionId)
        {
            var transactions = new GetTransactionsQuery(transactionId);

            var result = await mediator.Send(transactions);

            return(StatusCode((int)result.Code, result.Value));
        }
コード例 #9
0
        public async Task GivenValidQueryParams_WhenGetIsInvoked_ThenReturnsAListOfTransactions()
        {
            var transaction1 = new Transaction
            {
                Amount               = (decimal)1.0,
                Category             = "category-1",
                TransactionTimestamp = DateTime.Now.ToString("O"),
                Subcategory          = "subcategory-1",
                TransactionId        = "transaction-id-1",
                TransactionType      = "expense",
                PayerPayeeId         = Guid.NewGuid().ToString(),
                PayerPayeeName       = "name1",
                UserId               = "userid-1"
            };

            var transaction2 = new Transaction
            {
                Amount               = (decimal)2.0,
                Category             = "category-2",
                TransactionTimestamp = DateTime.Now.ToString("O"),
                Subcategory          = "subcategory-2",
                TransactionId        = "transaction-id-2",
                TransactionType      = "expense",
                PayerPayeeId         = Guid.NewGuid().ToString(),
                PayerPayeeName       = "name2",
                UserId               = "userid-2"
            };

            var expectedTransactionList = new List <Transaction>
            {
                transaction1, transaction2
            };

            var startDate  = DateTime.MinValue;
            var endDate    = DateTime.MaxValue;
            var type       = TransactionType.Expense;
            var inputQuery = new GetTransactionsQuery
            {
                Start = startDate,
                End   = endDate,
                Type  = type
            };

            _mockTransactionHelperService.Setup(service =>
                                                service.GetTransactionsAsync(inputQuery))
            .ReturnsAsync(expectedTransactionList);

            var controller = new TransactionsController(_mockTransactionHelperService.Object);
            var response   = await controller.Get(inputQuery);

            var objectResult = Assert.IsType <OkObjectResult>(response);

            var transactionList = objectResult.Value as List <Transaction>;

            Assert.NotNull(transactionList);
            Assert.Equal(expectedTransactionList, transactionList);
        }
コード例 #10
0
        public async Task CanGetTransactionsAsync()
        {
            GetTransactionsQuery query = new GetTransactionsQuery
            {
                WalletId = "1735613459"
            };

            Assert.NotEmpty((await walletController.GetTransactions(query)).Value);
        }
コード例 #11
0
        public async Task <List <Transaction> > GetTransactionsAsync(GetTransactionsQuery queryParams)
        {
            var dateRange = new DateRange(queryParams.Start.GetValueOrDefault(DateTime.MinValue),
                                          queryParams.End.GetValueOrDefault(DateTime.MaxValue));
            var spec = _specificationFactory.Create(queryParams);

            var filteredTransactions = await _repository.GetTransactions(_userContext.UserId, dateRange, spec);

            return(filteredTransactions);
        }
コード例 #12
0
        public async Task <ActionResult <PagedTransactionsVm> > GetPagedTransactions(Guid accountId, int page, int size)
        {
            try
            {
                var getTransactionsQuery = new GetTransactionsQuery()
                {
                    AccountId = accountId, Page = page, Size = size
                };
                var dtos = await _mediator.Send(getTransactionsQuery);

                return(Ok(dtos));
            }
            catch (Exception e)
            {
                _logger.LogError("Get transactions failed:" + e.Message);
                throw;
            }
        }
コード例 #13
0
        public void PassValidAccountNumber_ValidationSucceded()
        {
            // arrange
            var     mockApplicationDbContext = new Mock <IApplicationDbContext>();
            var     accountNumber            = "ABC123";
            Account account = new()
            {
                AccountNumber = accountNumber,
                Currency      = Currency.EUR
            };
            List <Account> accounts = new List <Account>()
            {
                account,
                new()
                {
                    AccountNumber = "DEF123"
                }
            };

            var stubAccounts = new StubListOfEntities <Account>(accounts);

            mockApplicationDbContext
            .Setup(m => m.Accounts)
            .Returns(stubAccounts);
            var sut = new GetTransactionQueryValidator(mockApplicationDbContext.Object);

            // act
            var instanceToValidate = new GetTransactionsQuery()
            {
                AccountNumber = accountNumber
            };
            var validationResult = sut.Validate(instanceToValidate);

            // assert
            validationResult.IsValid.Should().BeTrue();
        }
    }
}
コード例 #14
0
        public async Task <ActionResult <IEnumerable <TransactionModel> > > GetTransactions([FromQuery] Paging paging, [FromQuery] Filter filter, [FromQuery] Order?order)
        {
            var query = new GetTransactionsQuery
            {
                Paging = paging,
                Filter = filter,
                Order  = order
            };

            HttpContext.AddCachePrefernces(query);

            var result = await Mediator.Send(query, HttpContext.RequestAborted)
                         .ConfigureAwait(false);

            if (result.IsFailure)
            {
                return(result.Error.AsErrorActionResult());
            }

            HttpContext.AddPaging(result.Value.Paging);
            HttpContext.AddFromCacheHeader(query);

            return(Ok(result.Value.Transactions));
        }
コード例 #15
0
 public async Task <IEnumerable <UserTransaction> > Handle(GetTransactionsQuery request, CancellationToken cancellationToken)
 {
     return(_repository.GetAllTransactions());
 }
        public async Task <PagedResultDto <TransactionByIdDto> > HandleAsync(GetTransactionsQuery query)
        {
            var result = await this.repo.GetPageAsync(query.PageSize, query.PageToken).ConfigureAwait(false);

            return(result.ToPagedResultDto(model => model.ToDto()));
        }
コード例 #17
0
 public async Task <ActionResult <List <TransactionItem> > > GetTransactionsReportWithPagination([FromQuery] GetTransactionsQuery query)
 {
     return(await Mediator.Send(query));
 }
コード例 #18
0
        public async Task <IEnumerable <TransactionDto> > BrowseTransactionsAsync(GetTransactionsQuery query)
        {
            var transactions = await transactionRepository.GetAllAsync();

            return(mapper.Map <IEnumerable <TransactionDto> >(transactions));
        }
コード例 #19
0
 public async Task <ActionResult <IEnumerable <Transaction> > > GetTransactions(GetTransactionsQuery query)
 {
     return(await _context.Transactions.Where(x => x.WalletId == query.WalletId).Take(50).ToListAsync());
 }
コード例 #20
0
        public async Task <IActionResult> GetAll([FromQuery] GetTransactionsQuery query)
        {
            var result = await transactionService.BrowseTransactionsAsync(query);

            return(Ok(result));
        }
コード例 #21
0
 public Task <List <Data.Entity.Transaction> > HandleAsync(GetTransactionsQuery query)
 {
     return(query.ApplyTo(_context.Transactions.AsQueryable()).ToListAsync());
 }
コード例 #22
0
        public virtual async Task <QueryResponseBO <List <UserDepositContract> > > Handle(GetTransactionsQuery request, CancellationToken cancellationToken)
        {
            var credential = await _dataLayer.TblIdentityCredentials
                             .AsNoTracking()
                             .FirstOrDefaultAsync(i => i.Cuid == request.Cuid.ToString(), cancellationToken: cancellationToken);

            if (credential == null)
            {
                return(new()
                {
                    Message = $"Identity does not exist",
                    HttpStatusCode = HttpStatusCode.NotFound
                });
            }

            var result = await _dataLayer.TblUserDepositRequests
                         .Include(i => i.Gateway)
                         .Include(i => i.Currency)
                         .Include(i => i.TargetWalletType)
                         .Where(i => i.UserAuthId == credential.Id)
                         .AsNoTracking()
                         .ToListAsync(cancellationToken);

            if (!result.Any())
            {
                return(new()
                {
                    Message = $"No transaction records exist",
                    HttpStatusCode = HttpStatusCode.NoContent
                });
            }

            var r = result.Adapt <List <UserDepositContract> >();

            return(new ()
            {
                HttpStatusCode = HttpStatusCode.Accepted,
                Response = r
            });
        }
コード例 #23
0
 public async Task <ActionResult <IEnumerable <Transaction> > > GetTransactions(GetTransactionsQuery command)
 {
     return(await _txReadService.GetTransactions(command));
 }