BicepBuddyApp/src/main/java/User/UserController.java
@SuppressWarnings("unchecked")
	public void editUser(String email, String fName, String lName, Object style, Object timeOfDay,
			Object gender, Object prefGender, Object freq, Object goal, Object weight, Object exp,
			String age, String phone) {

		// Create the JSON to post to the API
		JSONObject editProfileJSON = new JSONObject();
		editProfileJSON.put("firstname", fName);
		editProfileJSON.put("lastname", lName);
		editProfileJSON.put("email", email);
		editProfileJSON.put("phoneNumber", phone);
		editProfileJSON.put("age", age);
		editProfileJSON.put("gender", (String) gender);
		editProfileJSON.put("preferredGender", (String) prefGender);
		editProfileJSON.put("goals", (String) goal);
		editProfileJSON.put("frequency", (String) freq);
		editProfileJSON.put("timeOfDay", (String) timeOfDay);
		editProfileJSON.put("workoutStyle", (String) style);
		editProfileJSON.put("weight", (String) weight);
		editProfileJSON.put("experience", (String) exp);

		// Actual DB edit User
		// Open the post response
		HttpPatch request = new HttpPatch(baseUrl + user.getId());

		try {
			// Set headers
			request.addHeader("content-type", "application/json");
			request.addHeader("Authorization", "Bearer " + user.getJwt());
			request.addHeader("id", user.getId());

			// Attach Body
			StringEntity params = new StringEntity(editProfileJSON.toJSONString());
			request.setEntity(params);

			// Execute the request
			HttpResponse response = httpClient.execute(request);

			// Get the Respose Back
		    if(response.getStatusLine().getStatusCode() == 200) {
		    	// SUCCESS!

		    	// Update User info from DB
		    	user.updateUser(email, fName, lName, style, timeOfDay, gender,
		    			prefGender, freq, goal, weight, exp, age, phone);

		    	// Indicate save and load profile
		    	Master.getInstance().updateFrame(new ProfileView());
		    	Master.appLogger.info(":: Editing user " + user.getfName() + " " + user.getlName() + ".");
		    	SettingsView.saved();
		    } else {
		    	// FAIL!
		    	Master.getInstance().updateFrame(new ProfileView());
		    	new ErrorGUI("Your changes couldn't be saved!");
		    }


		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			request.releaseConnection();
		}
	}
/**
	 * Edits the user and updates user on the DB.
	 *
	 * @param email the email
	 * @param fName the f name
	 * @param lName the l name
	 * @param style the style
	 * @param timeOfDay the time of day
	 * @param gender the gender
	 * @param prefGender the pref gender
	 * @param freq the freq
	 * @param goal the goal
	 * @param weight the weight
	 * @param exp the exp
	 * @param age the age
	 * @param phone the phone
	 */
Edits the user and updates user on the DB.
Edits the user and updates user on the DB .
@SuppressWarnings("unchecked")
	public void editUser(String email, String fName, String lName, Object style, Object timeOfDay,
			Object gender, Object prefGender, Object freq, Object goal, Object weight, Object exp,
			String age, String phone) {
		JSONObject editProfileJSON = new JSONObject();
		editProfileJSON.put("firstname", fName);
		editProfileJSON.put("lastname", lName);
		editProfileJSON.put("email", email);
		editProfileJSON.put("phoneNumber", phone);
		editProfileJSON.put("age", age);
		editProfileJSON.put("gender", (String) gender);
		editProfileJSON.put("preferredGender", (String) prefGender);
		editProfileJSON.put("goals", (String) goal);
		editProfileJSON.put("frequency", (String) freq);
		editProfileJSON.put("timeOfDay", (String) timeOfDay);
		editProfileJSON.put("workoutStyle", (String) style);
		editProfileJSON.put("weight", (String) weight);
		editProfileJSON.put("experience", (String) exp);
		HttpPatch request = new HttpPatch(baseUrl + user.getId());
		try {
			request.addHeader("content-type", "application/json");
			request.addHeader("Authorization", "Bearer " + user.getJwt());
			request.addHeader("id", user.getId());
			StringEntity params = new StringEntity(editProfileJSON.toJSONString());
			request.setEntity(params);
			HttpResponse response = httpClient.execute(request);
		    if(response.getStatusLine().getStatusCode() == 200) {
		    	user.updateUser(email, fName, lName, style, timeOfDay, gender,
		    			prefGender, freq, goal, weight, exp, age, phone);
		    	Master.getInstance().updateFrame(new ProfileView());
		    	Master.appLogger.info(":: Editing user " + user.getfName() + " " + user.getlName() + ".");
		    	SettingsView.saved();
		    } else {
		    	Master.getInstance().updateFrame(new ProfileView());
		    	new ErrorGUI("Your changes couldn't be saved!");
		    }
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			request.releaseConnection();
		}
	}
@ SuppressWarnings ( "unchecked" ) public void editUser ( String email , String fName , String lName , Object style , Object timeOfDay , Object gender , Object prefGender , Object freq , Object goal , Object weight , Object exp , String age , String phone ) { JSONObject editProfileJSON = new JSONObject ( ) ; editProfileJSON . put ( "firstname" , fName ) ; editProfileJSON . put ( "lastname" , lName ) ; editProfileJSON . put ( "email" , email ) ; editProfileJSON . put ( "phoneNumber" , phone ) ; editProfileJSON . put ( "age" , age ) ; editProfileJSON . put ( "gender" , ( String ) gender ) ; editProfileJSON . put ( "preferredGender" , ( String ) prefGender ) ; editProfileJSON . put ( "goals" , ( String ) goal ) ; editProfileJSON . put ( "frequency" , ( String ) freq ) ; editProfileJSON . put ( "timeOfDay" , ( String ) timeOfDay ) ; editProfileJSON . put ( "workoutStyle" , ( String ) style ) ; editProfileJSON . put ( "weight" , ( String ) weight ) ; editProfileJSON . put ( "experience" , ( String ) exp ) ; HttpPatch request = new HttpPatch ( baseUrl + user . getId ( ) ) ; try { request . addHeader ( "content-type" , "application/json" ) ; request . addHeader ( "Authorization" , "Bearer " + user . getJwt ( ) ) ; request . addHeader ( "id" , user . getId ( ) ) ; StringEntity params = new StringEntity ( editProfileJSON . toJSONString ( ) ) ; request . setEntity ( params ) ; HttpResponse response = httpClient . execute ( request ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) == 200 ) { user . updateUser ( email , fName , lName , style , timeOfDay , gender , prefGender , freq , goal , weight , exp , age , phone ) ; Master . getInstance ( ) . updateFrame ( new ProfileView ( ) ) ; Master . appLogger . info ( ":: Editing user " + user . getfName ( ) + " " + user . getlName ( ) + "." ) ; SettingsView . saved ( ) ; } else { Master . getInstance ( ) . updateFrame ( new ProfileView ( ) ) ; new ErrorGUI ( "Your changes couldn't be saved!" ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { request . releaseConnection ( ) ; } }
Edits the user and updates user on the DB.
Edits the user and updates user on the DB .
// Create the JSON to post to the API // Actual DB edit User // Open the post response // Set headers // Attach Body // Execute the request // Get the Respose Back // SUCCESS! // Update User info from DB // Indicate save and load profile // FAIL!