-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added solution to method UserService and AuthenticationService #749
base: master
Are you sure you want to change the base?
Conversation
@@ -11,6 +14,12 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService service = new UserService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make UserService class field
@@ -11,6 +14,12 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService service = new UserService(); | |||
Optional<User> user = Optional.ofNullable(service.findByEmail(email)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason for using Optional here - it makes code more difficult
Optional is useful for method return type (like a warning - we possibly have null inside)
Replaced ref to UserService as a class field; Removed 'Optional'.
Replaced ref to UserService as a class field; |
Replaced ref to UserService as a class field; Removed Optional
if (user != null) { | ||
return user.getPassword().equals(password); | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify it in one line using one return, at first check user != null && condition for email
No description provided.