-
Notifications
You must be signed in to change notification settings - Fork 948
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
Login and find user services created #899
base: master
Are you sure you want to change the base?
Conversation
@@ -10,7 +12,14 @@ public class AuthenticationService { | |||
* @return true if user by email exists and passed password is equal to user's password. | |||
* Return false in any other cases. | |||
*/ | |||
private UserService usersData = 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.
Let's call just this variable as it is - userService
Because it's not just the data, it also has a functionality that we can and should use :)
for (User user: usersData.getUsers()) { | ||
if (user.getEmail().equals(email) && user.getPassword().equals(password)) { | ||
return true; | ||
} | ||
} |
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.
Let's use findByEmail()
method from userService
to not duplicate our logic and here we can just do the null check and password check
for (User user: usersData.getUsers()) { | |
if (user.getEmail().equals(email) && user.getPassword().equals(password)) { | |
return true; | |
} | |
} |
|
||
public User[] getUsers() { | ||
return users; | ||
} |
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.
And we can remove this method
public User[] getUsers() { | |
return users; | |
} |
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.
GJ! Left a comment ragarding your question and some code style
// I'm not sure what better, to call 2 times find by email | ||
// methoud, or made an instance of find by email result? | ||
if (userService.findByEmail(email) != null) { | ||
if (userService.findByEmail(email).getPassword().equals(password)) { |
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.
we should always strive for DRY principle - which stands for Don't Repeat Yourself, including situations like this, when we can put the result of this method in a variable to not call it 2 times
Also, we can remove those if
statements, combine their condition into a single one and return it's result right away :)
return true; | ||
} | ||
} | ||
|
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.
redundant empty line
return null; | ||
} | ||
|
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.
same here
No description provided.