예제 #1
0
        /**
         * Set user preferences.
         */
        private async Task <APIGatewayProxyResponse> SetUserPreferences(IDataStores dataStores,
                                                                        IDictionary <string, string> requestHeaders,
                                                                        JObject requestBody)
        {
            Debug.Untested();
            Debug.AssertValid(dataStores);
            Debug.AssertValid(requestHeaders);
            Debug.AssertValidOrNull(requestBody);

            try {
                // Log call
                LoggingHelper.LogMessage($"UserIdentityService::SetUserPreferences()");

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

                // Check inputs
                SetUserPreferencesRequest setUserPreferencesRequest = UserIdentityService_SetUserPreferences_LogicLayer.CheckValidSetUserPreferencesRequest(requestBody);
                Debug.AssertValid(setUserPreferencesRequest);

                // Check authenticated endpoint security
                string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders);

                Debug.AssertID(loggedInUserId);

                // Perform logic
                await UserIdentityService_SetUserPreferences_LogicLayer.SetUserPreferences(dbClient, loggedInUserId, setUserPreferencesRequest);

                // Respond
                return(new APIGatewayProxyResponse {
                    StatusCode = APIHelper.STATUS_CODE_NO_CONTENT
                });
            } catch (Exception exception) {
                Debug.Tested();
                return(APIHelper.ResponseFromException(exception));
            }
        }
예제 #2
0
        /**
         * Set user preferences.
         */
        public static async Task SetUserPreferences(AmazonDynamoDBClient dbClient, string loggedInUserId, SetUserPreferencesRequest setUserPreferencesRequest)
        {
            Debug.Tested();
            Debug.AssertValid(dbClient);
            Debug.AssertID(loggedInUserId);
            Debug.AssertValid(setUserPreferencesRequest);

            // Load the user
            User user = await IdentityServiceLogicLayer.FindUserByID(dbClient, loggedInUserId);

            Debug.AssertValid(user);

            // Make changes (if necessary)
            if ((user.PreferredLanguage != setUserPreferencesRequest.preferredLanguage) ||
                (user.PreferredCurrency != setUserPreferencesRequest.preferredCurrency) ||
                (user.PreferredTimeZone != setUserPreferencesRequest.preferredTimeZone))
            {
                user.PreferredLanguage = setUserPreferencesRequest.preferredLanguage;
                user.PreferredCurrency = setUserPreferencesRequest.preferredCurrency;
                user.PreferredTimeZone = setUserPreferencesRequest.preferredTimeZone;

                // Save the user
                await IdentityServiceDataLayer.SaveUser(dbClient, user);
            }
        }