ADD::Added checkstyle comments
FIX::fixed some checkstyle warnings
This commit is contained in:
@@ -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,6 +97,12 @@ 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
|
||||
*/
|
||||
public void handleRegisterButtonAction(ActionEvent event) throws Exception {
|
||||
//load the fxml file
|
||||
Parent registerWindow = FXMLLoader.load(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import org.springframework.data.repository.CrudRepository;
|
||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||
// User findByName(@Param("name") String name);
|
||||
User findByName(String name);
|
||||
|
||||
User findById(Long id);
|
||||
|
||||
<T extends User> T save(T user);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,16 +17,22 @@ public class MainController {
|
||||
// Which is auto-generated by Spring, we will use it to handle the data
|
||||
private UserRepository userRepository;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user