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

add findByLogin and login foo #1158

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

Conversation

MykolaTurak
Copy link

No description provided.

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Good job! Let’s improve your solution ;)

@@ -15,6 +15,12 @@ public class UserService {
* Return <code>null</code> if there is no suitable user
*/
public User findByEmail(String email) {
for (int i = 0; i < users.length; i++) {

Choose a reason for hiding this comment

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

Can you use a for-each loop?

return null;
}

Choose a reason for hiding this comment

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

Suggested change

@@ -11,6 +13,14 @@ public class AuthenticationService {
* Return false in any other cases.
*/
public boolean login(String email, String password) {
UserService userService = new UserService();

Choose a reason for hiding this comment

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

make it a class-level variable (private final)

@@ -11,6 +13,14 @@ public class AuthenticationService {
* Return false in any other cases.
*/
public boolean login(String email, String password) {
UserService userService = new UserService();
if (userService.findByEmail(email) == null) {

Choose a reason for hiding this comment

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

Can you call the method findByEmail only once? Let’s think about how to refactor this method

@MykolaTurak MykolaTurak requested a review from JJJazl December 25, 2024 15:47
if (user == null) {
return false;
}
return user != null && user.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.

You check that user != null above, so we don't need to do it again

Suggested change
return user != null && user.getPassword().equals(password);
return user.getPassword().equals(password);

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.

3 participants