ADD::Added checkstyle comments
FIX::fixed some checkstyle warnings
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<User> getAllUsers() {
|
||||
// This returns a JSON or XML with the users
|
||||
return userRepository.findAll();
|
||||
|
||||
@@ -33,6 +33,6 @@ public class UserController {
|
||||
|
||||
@GetMapping("/getUsername")
|
||||
public void getUsername(@RequestParam(value = "id") Long id) {
|
||||
userService.getUsername(id);
|
||||
userService.getUsername(id);
|
||||
}
|
||||
}
|
||||
@@ -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