public async Task <APIGatewayProxyResponse> Coin(APIGatewayProxyRequest request, ILambdaContext context)
        {
            _logger.Log($"{nameof(Coin)} API called.");

            if (request.PathParameters == null || !request.PathParameters.ContainsKey(SYMBOL_PARAM_NAME))
            {
                return new APIGatewayProxyResponse {
                           StatusCode = (int)HttpStatusCode.BadRequest, Body = $"Missing required parameter {SYMBOL_PARAM_NAME}"
                }
            }
            ;

            var symbol = HttpUtility.UrlDecode(request.PathParameters[SYMBOL_PARAM_NAME]);

            if (!_coinRepository.CoinExists(symbol))
            {
                return new APIGatewayProxyResponse {
                           StatusCode = (int)HttpStatusCode.NotFound, Body = $"Symbol not found: {symbol}"
                }
            }
            ;

            var coinStats = await _coinRepository.GetCoinStats(symbol);

            return(CreateAPIGatewayProxyResponse(coinStats));
        }
Beispiel #2
0
 public CoinRepository(ICoinGeckoClient coinGeckoClient, IMemoryCache memoryCache, ICoinLogger coinLogger)
 {
     coinLogger.Log($"Initializing {nameof(CoinRepository)}.");
     _coinGeckoClient    = coinGeckoClient;
     _memoryCache        = memoryCache;
     _coinLogger         = coinLogger;
     _coins              = CoinData.GetAllCoins().Where(x => x.MarketCapRank > 0).GroupBy(x => x.Symbol).Select(x => x.OrderBy(y => y.MarketCapRank).First()).ToList();
     _coinBySymbolLookup = _coins.ToDictionary(x => x.Symbol, x => x);
 }