/** * Get the countries. */ public async Task <APIGatewayProxyResponse> GetCountries(IDataStores dataStores, APIGatewayProxyRequest request) { Debug.Tested(); Debug.AssertValid(dataStores); Debug.AssertValid(request); try { // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Security check User user = await APIHelper.CheckLoggedInAsAdmin(dbClient, request.Headers); Debug.AssertValid(user); // Get response information IEnumerable <Country> countries = await CountryServiceLogicLayer.GetCountries(dbClient); Debug.AssertValid(countries); // Return response return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_OK, Body = JsonConvert.SerializeObject(countries) }); } catch (Exception exception) { Debug.Unreachable(); return(APIHelper.ResponseFromException(exception)); } }
/** * Get the countries. */ public async Task <APIGatewayProxyResponse> GetCountries(IDataStores dataStores) { Debug.Tested(); Debug.AssertValid(dataStores); try { // Get the NoSQL DB client AmazonDynamoDBClient dbClient = dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Get response information IEnumerable <Country> countries = await CountryServiceLogicLayer.GetCountries(dbClient); Debug.AssertValid(countries); GetCountriesResponse responseBody = new GetCountriesResponse(); List <GetCountryResponse> availableCountries = new List <GetCountryResponse>(); foreach (Country country in countries) { Debug.Tested(); Debug.AssertValid(country); if (country.Available) { Debug.Tested(); availableCountries.Add(new GetCountryResponse { code = country.Code, name = country.Name, currencies = country.Currencies.ToArray() }); } else { Debug.Tested(); } } responseBody.countries = availableCountries.ToArray(); // Return response return(new APIGatewayProxyResponse { StatusCode = STATUS_CODE_OK, Body = JsonConvert.SerializeObject(responseBody) }); } catch (Exception exception) { Debug.Unreachable(); return(APIHelper.ResponseFromException(exception)); } }