Beispiel #1
0
        /**
         * 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));
            }
        }
Beispiel #2
0
        /**
         * Get the countries.
         */
        public async Task <APIGatewayProxyResponse> UpdateCountry(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody)
        {
            Debug.Tested();
            Debug.AssertValid(dataStores);
            Debug.AssertValid(requestHeaders);
            Debug.AssertValidOrNull(requestBody);

            try {
                // Log call
                LoggingHelper.LogMessage($"AdminCountryService::UpdateCountry()");

                // Get the NoSQL DB client
                AmazonDynamoDBClient dbClient = dataStores.GetNoSQLDataStore().GetDBClient();
                Debug.AssertValid(dbClient);

                // Check inputs
                Country country = CountryServiceLogicLayer.CheckValidUpdateCountryRequest(requestBody);

                // Check security
                User user = await APIHelper.CheckLoggedInAsAdmin(dbClient, requestHeaders);

                Debug.AssertValid(user);

                // Perform logic
                bool created = await CountryServiceLogicLayer.UpdateCountry(dbClient, loggedInUserId, country);

                // Return response
                return(new APIGatewayProxyResponse
                {
                    StatusCode = created ? APIHelper.STATUS_CODE_CREATED : APIHelper.STATUS_CODE_NO_CONTENT
                });
            } catch (Exception exception) {
                Debug.Unreachable();
                return(APIHelper.ResponseFromException(exception));
            }
        }