public static async Task <IActionResult> GetValues(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "customerPortfolio/{customerId}")] HttpRequest req,
            string customerId,
            ILogger log)
        {
            // TODO validate input
            var portfolioRepo = new CustomerPortfolioRepository(log);

            log.LogInformation($"customerPortfolio endpoint called for {customerId}.");
            var portfolio = await portfolioRepo.GetCustomerPortfolioSymbols(customerId);

            log.LogInformation($"Customer {customerId} has '{portfolio}' symbols.");

            var quoteRepo = new QuoteRepository(log);

            var result = new List <StockValue>();

            foreach (var symbol in portfolio)
            {
                var quote = await quoteRepo.GetSymbolQuote(symbol);

                var value = new StockValue
                {
                    Symbol        = symbol,
                    Quote         = quote.Value,
                    FailureReason = quote.FailureReason
                };
                result.Add(value);
            }

            // TODO failure cases
            return(new OkObjectResult(result));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "health/{depth}")] HttpRequest req,
            string depth,
            ILogger log)
        {
            log.LogInformation($"health endpoint called for {depth}.");

            switch (depth.ToLowerInvariant())
            {
            case "dependencies":
                var portfolioRepo = new CustomerPortfolioRepository(log);
                await portfolioRepo.HealthCheck();

                var quoteRepo = new QuoteRepository(log);
                await quoteRepo.HealthCheck();

                // TODO detailed output on which dependencies breaks
                break;

            case "basic":
                break;

            default:
                goto case "basic";
            }

            return((ActionResult) new OkObjectResult($"healthy"));
        }
        public static async Task <IActionResult> Upsert(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "customerPortfolio/{customerId}")] HttpRequest req,
            string customerId,
            ILogger log)
        {
            // TODO validate input
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  symbol      = data?.symbol;

            log.LogInformation($"customerPortfolio endpoint (POST) called for {customerId} and {symbol}.");

            var repo = new CustomerPortfolioRepository(log);
            // TODO error handling
            await repo.AddSymbolToCustomerPortfolio(customerId, symbol);

            return(new OkObjectResult("ok"));
        }