public static async Task <IActionResult> GetAllStationsForecast( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stations/all/forecast")] HttpRequest req, ILogger log) { log.LogInformation($"Get station forecast for all stations"); LuasApi api = new LuasApi(); var stations = api.GetAllStations(); var stationAbbreviations = stations.Select(s => s.Abbreviation); try { var allForecasts = await Task.WhenAll( stationAbbreviations.Select( abbreviation => api.GetForecastAsync(abbreviation))) .ConfigureAwait(false); var allForecastsDictionary = allForecasts.Select(forecast => new { forecast.Station.Abbreviation, forecast }); return(new OkObjectResult(allForecastsDictionary)); } catch (StationNotFoundException ex) { log.LogWarning($"StationNotFoundException for '{ex.StationThatWasNotFound}'. Exception: {ex}"); return(new NotFoundObjectResult($"Unable to find forecast for: '{ex.StationThatWasNotFound}'")); } catch (Exception ex) { log.LogError($"Exception thrown in GetStationForecast. Exception: {ex}"); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public static async Task <IActionResult> GetAllStations( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stations")] HttpRequest req, ILogger log) { log.LogInformation("Get all stations"); LuasApi api = new LuasApi(); return(new OkObjectResult(api.GetAllStations())); }