public async Task <CommandResult <List <DownstreamObjectDto> > > AggregateObjects() { var request = await _responseProcessor.CreateAsync(HttpMethod.Get, $"{_configs["Servers:Catalog"]}/api/object/list", true, true, null); try { var response = await _httpClient.SendAsync(request); var objectResult = await _responseProcessor.Process <List <UpstreamObjectDto> >(response); if (!objectResult.IsSuccessful) { return(new CommandResult <List <DownstreamObjectDto> >(objectResult.Error)); } var originalUserIds = objectResult.Result.Select(o => o.OwnerId).ToList(); var users = await _userService.GetUsersAsync(originalUserIds); return(new CommandResult <List <DownstreamObjectDto> >(ReplaceUserIdWithUser(objectResult.Result, users))); } catch (Exception e) { _logger.LogError(e, "Error When getting list of objects"); var message = new ErrorMessage { ErrorCode = "CATALOG.OBJECT.LIST.ERROR", Message = "there were an error while trying to execute your request", StatusCode = System.Net.HttpStatusCode.InternalServerError, }; return(new CommandResult <List <DownstreamObjectDto> >(message)); } }
public async Task <CommandResult <TransactionForUserDownstreamListDto> > GetTransactions() { var request = await _responseProcessor.CreateAsync(_httpContext, HttpMethod.Get, $"{_configs["Services:Transaction"]}/api/Transaction/foruser", true, true, changeBody : null); try { var response = await _httpClient.SendAsync(request); var transactionsResult = await _responseProcessor.Process <List <TransactionUpstreamDto> >(response); if (!transactionsResult.IsSuccessful) { return(new CommandResult <TransactionForUserDownstreamListDto>(transactionsResult.Error)); } var originalUserIds = transactionsResult.Result.Select(o => o.OwnerId) .Union(transactionsResult.Result.Select(o => o.ReceiverId)) .Distinct() .ToList(); var users = await _userService.GetUsersAsync(originalUserIds); var objectsIds = transactionsResult.Result.Select(t => t.ObjectId).ToList(); var objects = await _objectService.GetObjectsByIds(objectsIds); return(new CommandResult <TransactionForUserDownstreamListDto>(AggregateTransactionWithObject8User(transactionsResult.Result, users, objects))); } catch (Exception e) { _logger.LogError(e, "Error When getting list of transactions that belog to user"); var message = new ErrorMessage { ErrorCode = "TRANSACTION.LIST.FORUSER.ERROR", Message = "there were an error while trying to execute your request", StatusCode = System.Net.HttpStatusCode.InternalServerError, }; return(new CommandResult <TransactionForUserDownstreamListDto>(message)); } }