Пример #1
0
        public async Task <IActionResult> GetInvestment([FromRoute] Guid userId, [FromRoute] Guid accountId,
                                                        [FromQuery] int page = 1, [FromQuery] int size = 30)
        {
            var userInfo = this.GetUserInfo();

            if (!userId.Equals(userInfo.UserId) || !accountId.Equals(userInfo.AccountId))
            {
                return(BadRequest("Invalid token."));
            }

            var query  = new GetAllInvestmentsQuery(userInfo.UserId, userInfo.AccountId, page, size);
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
Пример #2
0
        public async Task <IEnumerable <GetAllInvestmentResponse> > Handle(GetAllInvestmentsQuery request,
                                                                           CancellationToken cancellationToken)
        {
            var investments = await _investmentRepository.GetInvestmentsByAccount(request.UserId,
                                                                                  request.AccountId, request.Page, request.PageSize);

            if (investments is null || !investments.Any())
            {
                return(Enumerable.Empty <GetAllInvestmentResponse>());
            }

            return(investments.Select(m => new GetAllInvestmentResponse
            {
                Id = m.Id,
                Value = m.Value,
                Description = m.Description,
                Type = m.Type,
                CreatedOn = m.CreatedOn
            }));
        }