public async Task <ActionResult <IEnumerable <CustomerAccount> > > GetByCustomerId( [SwaggerParameter("Customer identifier", Required = true)] int customerId) { _logger.LogInformation($"Get accounts for a {customerId}"); try { if (customerId <= 0) { _logger.LogWarning($"Invalid customer id: {customerId}"); return(BadRequest()); } List <CustomerAccount> customerAccounts = _mapper.Map <List <CustomerAccount> >(_customerAccountRepository.GetCustomerAccountsByCustomerId(customerId)); if (customerAccounts == null) { _logger.LogWarning($"No accounts found for customer {customerId}"); return(NotFound()); } _logger.LogInformation($"{customerAccounts.Count} accounts found for customer {customerId}"); foreach (var customerAccount in customerAccounts) { customerAccount.Transactions = await _transactionProxyService.GetTransactions(customerAccount.CustomerAccountId); } return(Ok(customerAccounts)); } catch (Exception ex) { _logger.LogError($"Error in {nameof(GetByCustomerId)} with customerId {customerId}. Details: {ex}"); return(StatusCode(500)); } }