Merge branch 'master' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template

This commit is contained in:
Sem van der Hoeven
2019-03-17 13:11:00 +01:00
76 changed files with 4830 additions and 556 deletions

View File

@@ -17,4 +17,16 @@ public class UserController {
@RequestParam(value = "password") String password) {
return userService.registerUser(name, password);
}
@RequestMapping("/loginUser")
public UserDTO loginUser(@RequestParam(value = "name") String name,
@RequestParam(value = "password") String password) {
return userService.loginUser(name, password);
}
@RequestMapping("/addVeganMeal")
public void addVeganMeal(@RequestParam(value = "id") Long id,
@RequestParam(value = "name") String name) {
userService.addVeganMeal(id, name);
}
}

View File

@@ -32,22 +32,37 @@ public class UserService {
return new UserDTO(user.getId(), user.getName());
}
/**
* logs the user in.
* @param name the username of the user
* @param password the password of the user
* @return a userDTO of the logged in user
*/
// public UserDTO login(String name, String password) {
// User user = userRepository.findByName(name);
// if (user == null) {
// throw new ApplicationException("User does not exist");
// } else {
// if (!user.getPassword().equals(password)) {
// throw new ApplicationException("Wrong password");
// }
// }
// return new UserDTO(user.getId(), user.getName());
// }
public UserDTO loginUser(String name, String password) {
User user = userRepository.findByName(name);
if (user == null) {
throw new ApplicationException("User does not exist");
} else {
if (!user.getPassword().equals(password)) {
throw new ApplicationException("Wrong password");
}
}
return new UserDTO(user.getId(), user.getName());
}
/**
* 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() + ")");
}
}