From e1448055f57dd4f9e03de773cb073f3030d319df Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Sun, 17 Mar 2019 15:58:55 +0100 Subject: [PATCH] ADD::Added checkstyle comments FIX::fixed some checkstyle warnings --- .../controller/DashBoardController.java | 8 +++---- .../controller/RegisterWindowController.java | 2 +- .../client/controller/UserController.java | 14 ++++++++--- .../java/greenify/server/data/model/User.java | 16 +++++++++---- .../data/repository/UserRepository.java | 2 ++ .../greenify/server/rest/MainController.java | 24 ++++++++++++------- .../greenify/server/rest/UserController.java | 2 +- .../greenify/server/service/UserService.java | 9 +++++-- 8 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 07b5392..f0f1ffb 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -48,10 +48,10 @@ public class DashBoardController { public void displayDashboard(ActionEvent event) { System.out.println("display dashboard"); -// UserService service = new UserService(); -// UserDTO user = service.getName(null); -// String name = user.getName(); -// welcomebacktext.setText("Welcome back, " + name); + // UserService service = new UserService(); + // UserDTO user = service.getName(null); + // String name = user.getName(); + // welcomebacktext.setText("Welcome back, " + name); dashboardPane.setVisible(true); userPane.setVisible(false); diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index a0e6a8b..df99252 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -33,7 +33,7 @@ public class RegisterWindowController { */ @FXML public void handleSignUpButton(ActionEvent event) { - //set the window to the current window (for displaying the alerts) + //set the window to the current window (for displaying the alerts) Window owner = signupButton.getScene().getWindow(); //check if the username field is empty if (userNameText.getText().isEmpty()) { diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index abf29a5..23c8a47 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -68,7 +68,9 @@ public class UserController { this.getClass().getClassLoader().getResource("fxml/dashboard.fxml") ); Scene scene = new Scene(dash); - scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/dashboardStyle.css").toExternalForm()); + scene.getStylesheets().add(getClass() + .getClassLoader() + .getResource("stylesheets/dashboardStyle.css").toExternalForm()); Stage appStage = new Stage(); appStage.setScene(scene); appStage.show(); @@ -95,9 +97,15 @@ public class UserController { } } - public void handleRegisterButtonAction(ActionEvent event) throws Exception{ + /** + * 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 + */ + public void handleRegisterButtonAction(ActionEvent event) throws Exception { //load the fxml file - Parent registerWindow = FXMLLoader.load ( + Parent registerWindow = FXMLLoader.load( this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml") ); //make the window use the scene diff --git a/src/Server/src/main/java/greenify/server/data/model/User.java b/src/Server/src/main/java/greenify/server/data/model/User.java index 89720f6..d2b8aa7 100644 --- a/src/Server/src/main/java/greenify/server/data/model/User.java +++ b/src/Server/src/main/java/greenify/server/data/model/User.java @@ -48,7 +48,9 @@ public class User { return id; } - public void setId(Long id) { this.id = id; } + public void setId(Long id) { + this.id = id; + } /** * gets the name. @@ -58,7 +60,9 @@ public class User { return name; } - public void setName(String name) { this.name = name; } + public void setName(String name) { + this.name = name; + } /** * gets the password. @@ -68,7 +72,9 @@ public class User { return password; } - public void setPassword(String password) { this.password = password; } + public void setPassword(String password) { + this.password = password; + } /** * gets the number of vegan meal. @@ -78,5 +84,7 @@ public class User { return veganMeal; } - public void setVeganMeal(int veganMeal) { this.veganMeal = veganMeal; } + public void setVeganMeal(int veganMeal) { + this.veganMeal = veganMeal; + } } diff --git a/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java b/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java index af4c6b7..1e8d910 100644 --- a/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java +++ b/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java @@ -6,7 +6,9 @@ import org.springframework.data.repository.CrudRepository; public interface UserRepository extends CrudRepository { // User findByName(@Param("name") String name); User findByName(String name); + User findById(Long id); + T save(T user); } diff --git a/src/Server/src/main/java/greenify/server/rest/MainController.java b/src/Server/src/main/java/greenify/server/rest/MainController.java index b985819..5cdb8f4 100644 --- a/src/Server/src/main/java/greenify/server/rest/MainController.java +++ b/src/Server/src/main/java/greenify/server/rest/MainController.java @@ -11,26 +11,32 @@ import greenify.server.data.model.User; import greenify.server.data.repository.UserRepository; @Controller // This means that this class is a Controller -@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path) +@RequestMapping(path = "/demo") // This means URL's start with /demo (after Application path) public class MainController { @Autowired // This means to get the bean called userRepository // Which is auto-generated by Spring, we will use it to handle the data private UserRepository userRepository; - @GetMapping(path="/add") // Map ONLY GET Requests - public @ResponseBody String addNewUser (@RequestParam String name - , @RequestParam String password) { + /** + * getmapping for adding a user. + * @param name the username of the user + * @param password the password of the user + * @return a response for adding the user, "saved", if it succeeded + */ + @GetMapping(path = "/add") // Map ONLY GET Requests + public @ResponseBody String addNewUser(@RequestParam String name, + @RequestParam String password) { // @ResponseBody means the returned String is the response, not a view name // @RequestParam means it is a parameter from the GET or POST request - User n = new User(); - n.setName(name); - n.setPassword(password); - userRepository.save(n); + User newuser = new User(); + newuser.setName(name); + newuser.setPassword(password); + userRepository.save(newuser); return "Saved"; } - @GetMapping(path="/all") + @GetMapping(path = "/all") public @ResponseBody Iterable getAllUsers() { // This returns a JSON or XML with the users return userRepository.findAll(); diff --git a/src/Server/src/main/java/greenify/server/rest/UserController.java b/src/Server/src/main/java/greenify/server/rest/UserController.java index 4db7703..908efd7 100644 --- a/src/Server/src/main/java/greenify/server/rest/UserController.java +++ b/src/Server/src/main/java/greenify/server/rest/UserController.java @@ -33,6 +33,6 @@ public class UserController { @GetMapping("/getUsername") public void getUsername(@RequestParam(value = "id") Long id) { - userService.getUsername(id); + userService.getUsername(id); } } \ No newline at end of file diff --git a/src/Server/src/main/java/greenify/server/service/UserService.java b/src/Server/src/main/java/greenify/server/service/UserService.java index e8baf64..cb6a895 100644 --- a/src/Server/src/main/java/greenify/server/service/UserService.java +++ b/src/Server/src/main/java/greenify/server/service/UserService.java @@ -55,16 +55,21 @@ public class UserService { * add vegan meal to the user. * @param id the id of the user * @param name the name of the user - * @return a userDTO of the user added vegan meal */ public void addVeganMeal(Long id, String name) { User user = userRepository.findByName(name); int count = user.getVeganMeal(); count++; user.setVeganMeal(count); - logger.info("Added vegan meal to user(id=" + user.getId() + ", name=" + user.getName() + ")"); + logger.info("Added vegan meal to user(id=" + + user.getId() + ", name=" + user.getName() + ")"); } + /** + * gets the username of the user with the specified id. + * @param id the id of the user + * @return the username of the user + */ public String getUsername(Long id) { User user = userRepository.findById(id); String name = user.getName();