Major refactor of reading from excel to db

This commit is contained in:
Maciek Głowacki
2020-09-21 17:45:52 +02:00
parent e91965e9b5
commit c449bc22e1
16 changed files with 158 additions and 167 deletions

View File

@ -19,11 +19,11 @@ public class UserService extends EventWatcher {
super();
}
// this code is more idiomatic to java using java 8 stream API
public String login(String authority) throws UserNotFoundException {
User user = this.repo.getByAuthority(authority.replace("\n", "").trim());
if (user == null) {
throw new UserNotFoundException("Can not find user with given authority");
}
User user = this.repo.getByAuthority(authority.replace("\n", "").trim())
.orElseThrow(() -> new UserNotFoundException("Can not find user with given authority"));
String token = UUID.randomUUID().toString();
user.setToken(token);
this.repo.save(user);
@ -34,10 +34,14 @@ public class UserService extends EventWatcher {
this.repo.save(user);
}
public User getUserByEmail(String email) {
return this.repo.getByAuthority(email.replace("\n", "").trim());
// this code is more idiomatic to java
public User getUserByEmail(String email) throws UserNotFoundException {
return this.repo.getByAuthority(email.replace("\n", "").trim())
.orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority"));
}
// why is not throwing exception?
public User getByToken(String token) {
return this.repo.getByToken(token);
}