Fix the branch and add a test

This commit is contained in:
cugurlu
2019-03-17 18:58:56 +01:00
parent 0c042daa1c
commit 1da7f62c95
9 changed files with 104 additions and 213 deletions

View File

@@ -1,9 +1,9 @@
package greenify.client.controller;
import greenify.client.Application;
import greenify.client.rest.UserService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
@@ -23,15 +23,9 @@ public class UserController {
UserService userService;
@FXML
public TextField usernameField;
@FXML
private TextField usernameField;
private PasswordField passwordField;
@FXML
private Button loginButton;
@FXML
private Button signupButton;
@FXML
@@ -64,12 +58,10 @@ public class UserController {
* @author sem
*/
public void openDashboard() throws IOException {
Parent dash = FXMLLoader.load(
this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")
);
Parent dash = Application.load(this.getClass().getClassLoader()
.getResource("fxml/dashboard.fxml"));
Scene scene = new Scene(dash);
scene.getStylesheets().add(getClass()
.getClassLoader()
scene.getStylesheets().add(getClass().getClassLoader()
.getResource("stylesheets/dashboardStyle.css").toExternalForm());
Stage appStage = new Stage();
appStage.setScene(scene);
@@ -98,21 +90,16 @@ public class UserController {
}
/**
* handles the click of the 'sign up' button.
* opens a new stage where the user can register.
* @param event the click of the button
* @throws Exception an exception if the fxml file is not found
* The method handles register button.
* @param event User clicks to the button
* @throws Exception when the file couldn't find
*/
public void handleRegisterButtonAction(ActionEvent event) throws Exception {
//load the fxml file
Parent registerWindow = FXMLLoader.load(
this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml")
);
//make the window use the scene
Scene registerscene = new Scene(registerWindow);
Parent registerWindow = Application.load(this.getClass().getClassLoader()
.getResource("fxml/RegisterWindow.fxml"));
Scene registerScene = new Scene(registerWindow);
Stage registerStage = new Stage();
//open the window
registerStage.setScene(registerscene);
registerStage.setScene(registerScene);
registerStage.setTitle("Enter register credentials");
registerStage.show();
}

View File

@@ -13,7 +13,6 @@ import org.springframework.web.util.UriComponentsBuilder;
@Service
public class UserService {
@Autowired
RestTemplate restTemplate;
@@ -28,9 +27,8 @@ public class UserService {
* registers the user.
* @param name the username of the user
* @param password the password of the user
* @return a built userDTO with the required information
* @return a userDTO
*/
@SuppressWarnings("Duplicates")
public UserDto registerUser(String name, String password) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
@@ -46,12 +44,11 @@ public class UserService {
}
/**
* logd the user in.
* sign ins the user.
* @param name the username of the user
* @param password the password of the user
* @return a built userDTO with the required information
* @return a userDTO
*/
@SuppressWarnings("Duplicates")
public UserDto loginUser(String name, String password) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
@@ -67,12 +64,11 @@ public class UserService {
}
/**
* adds a vegetarian meal to the user.
* a user adds vegan meal.
* @param id the id of the user
* @param name the username of the user
* @return a built userDTO with the required information
* @return a userDTO
*/
@SuppressWarnings("Duplicates")
public UserDto addVeganMeal(Long id, String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
@@ -83,20 +79,4 @@ public class UserService {
System.out.println(builder.build().encode().toUri());
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
}
/**
* gets the username from the user.
* @param id the id of the user
* @return a UserDTO with the required information
*/
@SuppressWarnings("Duplicates")
public UserDto getName(Long id) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getUsername")
.queryParam("id", id);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
}
}