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));
        }
        public async Task <ActionResult <IEnumerable <UserTransaction> > > GetTransactions()
        {
            var query  = new GetTransactionsQuery();
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Get([FromQuery] GetTransactionsQuery queryParams
                                              )
        {
            var result = await _transactionHelperService
                         .GetTransactionsAsync(queryParams);

            return(Ok(result));
        }
        public ActionResult Get()
        {
            // Send the query
            var query        = new GetTransactionsQuery();
            var transactions = query.Run();

            return(Ok(transactions));
        }
        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));
        }
        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);
        }
Exemplo n.º 10
0
        public async Task CanGetTransactionsAsync()
        {
            GetTransactionsQuery query = new GetTransactionsQuery
            {
                WalletId = "1735613459"
            };

            Assert.NotEmpty((await walletController.GetTransactions(query)).Value);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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();
        }
    }
}
Exemplo n.º 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));
        }
Exemplo n.º 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()));
        }
Exemplo n.º 17
0
 public async Task <ActionResult <List <TransactionItem> > > GetTransactionsReportWithPagination([FromQuery] GetTransactionsQuery query)
 {
     return(await Mediator.Send(query));
 }
Exemplo n.º 18
0
        public async Task <IEnumerable <TransactionDto> > BrowseTransactionsAsync(GetTransactionsQuery query)
        {
            var transactions = await transactionRepository.GetAllAsync();

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

            return(Ok(result));
        }
Exemplo n.º 21
0
 public Task <List <Data.Entity.Transaction> > HandleAsync(GetTransactionsQuery query)
 {
     return(query.ApplyTo(_context.Transactions.AsQueryable()).ToListAsync());
 }
Exemplo n.º 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
            });
        }
Exemplo n.º 23
0
 public async Task <ActionResult <IEnumerable <Transaction> > > GetTransactions(GetTransactionsQuery command)
 {
     return(await _txReadService.GetTransactions(command));
 }