ADD::Added checkstyle comments

FIX::fixed some checkstyle warnings
This commit is contained in:
Sem van der Hoeven
2019-03-17 15:58:55 +01:00
parent e718e3859b
commit e1448055f5
8 changed files with 53 additions and 24 deletions

View File

@@ -48,10 +48,10 @@ public class DashBoardController {
public void displayDashboard(ActionEvent event) { public void displayDashboard(ActionEvent event) {
System.out.println("display dashboard"); System.out.println("display dashboard");
// UserService service = new UserService(); // UserService service = new UserService();
// UserDTO user = service.getName(null); // UserDTO user = service.getName(null);
// String name = user.getName(); // String name = user.getName();
// welcomebacktext.setText("Welcome back, " + name); // welcomebacktext.setText("Welcome back, " + name);
dashboardPane.setVisible(true); dashboardPane.setVisible(true);
userPane.setVisible(false); userPane.setVisible(false);

View File

@@ -33,7 +33,7 @@ public class RegisterWindowController {
*/ */
@FXML @FXML
public void handleSignUpButton(ActionEvent event) { 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(); Window owner = signupButton.getScene().getWindow();
//check if the username field is empty //check if the username field is empty
if (userNameText.getText().isEmpty()) { if (userNameText.getText().isEmpty()) {

View File

@@ -68,7 +68,9 @@ public class UserController {
this.getClass().getClassLoader().getResource("fxml/dashboard.fxml") this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")
); );
Scene scene = new Scene(dash); 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(); Stage appStage = new Stage();
appStage.setScene(scene); appStage.setScene(scene);
appStage.show(); 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 //load the fxml file
Parent registerWindow = FXMLLoader.load ( Parent registerWindow = FXMLLoader.load(
this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml") this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml")
); );
//make the window use the scene //make the window use the scene

View File

@@ -48,7 +48,9 @@ public class User {
return id; return id;
} }
public void setId(Long id) { this.id = id; } public void setId(Long id) {
this.id = id;
}
/** /**
* gets the name. * gets the name.
@@ -58,7 +60,9 @@ public class User {
return name; return name;
} }
public void setName(String name) { this.name = name; } public void setName(String name) {
this.name = name;
}
/** /**
* gets the password. * gets the password.
@@ -68,7 +72,9 @@ public class User {
return password; return password;
} }
public void setPassword(String password) { this.password = password; } public void setPassword(String password) {
this.password = password;
}
/** /**
* gets the number of vegan meal. * gets the number of vegan meal.
@@ -78,5 +84,7 @@ public class User {
return veganMeal; return veganMeal;
} }
public void setVeganMeal(int veganMeal) { this.veganMeal = veganMeal; } public void setVeganMeal(int veganMeal) {
this.veganMeal = veganMeal;
}
} }

View File

@@ -6,7 +6,9 @@ import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Integer> { public interface UserRepository extends CrudRepository<User, Integer> {
// User findByName(@Param("name") String name); // User findByName(@Param("name") String name);
User findByName(String name); User findByName(String name);
User findById(Long id); User findById(Long id);
<T extends User> T save(T user); <T extends User> T save(T user);
} }

View File

@@ -11,26 +11,32 @@ import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository; import greenify.server.data.repository.UserRepository;
@Controller // This means that this class is a Controller @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 { public class MainController {
@Autowired // This means to get the bean called userRepository @Autowired // This means to get the bean called userRepository
// Which is auto-generated by Spring, we will use it to handle the data // Which is auto-generated by Spring, we will use it to handle the data
private UserRepository userRepository; private UserRepository userRepository;
@GetMapping(path="/add") // Map ONLY GET Requests /**
public @ResponseBody String addNewUser (@RequestParam String name * getmapping for adding a user.
, @RequestParam String password) { * @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 // @ResponseBody means the returned String is the response, not a view name
// @RequestParam means it is a parameter from the GET or POST request // @RequestParam means it is a parameter from the GET or POST request
User n = new User(); User newuser = new User();
n.setName(name); newuser.setName(name);
n.setPassword(password); newuser.setPassword(password);
userRepository.save(n); userRepository.save(newuser);
return "Saved"; return "Saved";
} }
@GetMapping(path="/all") @GetMapping(path = "/all")
public @ResponseBody Iterable<User> getAllUsers() { public @ResponseBody Iterable<User> getAllUsers() {
// This returns a JSON or XML with the users // This returns a JSON or XML with the users
return userRepository.findAll(); return userRepository.findAll();

View File

@@ -33,6 +33,6 @@ public class UserController {
@GetMapping("/getUsername") @GetMapping("/getUsername")
public void getUsername(@RequestParam(value = "id") Long id) { public void getUsername(@RequestParam(value = "id") Long id) {
userService.getUsername(id); userService.getUsername(id);
} }
} }

View File

@@ -55,16 +55,21 @@ public class UserService {
* add vegan meal to the user. * add vegan meal to the user.
* @param id the id of the user * @param id the id of the user
* @param name the name 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) { public void addVeganMeal(Long id, String name) {
User user = userRepository.findByName(name); User user = userRepository.findByName(name);
int count = user.getVeganMeal(); int count = user.getVeganMeal();
count++; count++;
user.setVeganMeal(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) { public String getUsername(Long id) {
User user = userRepository.findById(id); User user = userRepository.findById(id);
String name = user.getName(); String name = user.getName();