Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Recdt
Copy link

@Recdt Recdt commented Jan 7, 2024

No description provided.

@@ -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();
Copy link

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 :)

Comment on lines 18 to 22
for (User user: usersData.getUsers()) {
if (user.getEmail().equals(email) && user.getPassword().equals(password)) {
return true;
}
}
Copy link

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

Suggested change
for (User user: usersData.getUsers()) {
if (user.getEmail().equals(email) && user.getPassword().equals(password)) {
return true;
}
}

Comment on lines 25 to 28

public User[] getUsers() {
return users;
}
Copy link

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

Suggested change
public User[] getUsers() {
return users;
}

@Recdt Recdt requested a review from karma-o February 6, 2024 17:28
Copy link

@karma-o karma-o left a 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

Comment on lines +16 to +19
// 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)) {
Copy link

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;
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant empty line

Suggested change

return null;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants