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

Hometask done #898

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

Hometask done #898

wants to merge 10 commits into from

Conversation

skucherenko7
Copy link

No description provided.

Comment on lines 18 to 24
int i = 0;
while (i < users.length) {
if (users[i].getEmail().equals(email)) {
return users[i];
}
i++;
}

Choose a reason for hiding this comment

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

Here you better use for each loop

*/
public boolean login(String email, String password) {
return false;
UserService userService = new UserService();

Choose a reason for hiding this comment

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

UserService should be class field

Comment on lines 17 to 19
return Objects.requireNonNull(UserService.findByEmail(email)).getEmail().equals(email)
&& Objects.requireNonNull(UserService.findByEmail(email)).getPassword()
.equals(password);

Choose a reason for hiding this comment

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

You don`t need use class Objects here, at first you can get user form UserService.findByEmail(email) anf after this compare his password

Comment on lines 18 to 24

for (User user: users) {
if (user.getEmail().equals(email)) {
return user;
}
}

Choose a reason for hiding this comment

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

redundant blank lines

Suggested change
for (User user: users) {
if (user.getEmail().equals(email)) {
return user;
}
}
for (User user: users) {
if (user.getEmail().equals(email)) {
return user;
}
}

Choose a reason for hiding this comment

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

not fixed

Comment on lines 12 to 20

if (userService.findByEmail(email).getPassword().equals(password)) {
return true;
}
return false;
}
}


Choose a reason for hiding this comment

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

  1. many redundant blank lines
  2. we will get NPE if userService.findByEmail(email) returns null. save returned user to the variable and check for nullability

Choose a reason for hiding this comment

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

not fixed

@@ -1,16 +1,20 @@
package mate.academy.service;

public class AuthenticationService {
private static final UserService userService = new UserService();

Choose a reason for hiding this comment

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

Suggested change
private static final UserService userService = new UserService();
private final UserService userService = new UserService();

Choose a reason for hiding this comment

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

not fixed

@skucherenko7 skucherenko7 requested a review from kerrrusha January 9, 2024 19:09
@@ -1,16 +1,20 @@
package mate.academy.service;

public class AuthenticationService {
private static final UserService userService = new UserService();

Choose a reason for hiding this comment

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

not fixed

Comment on lines 12 to 20

if (userService.findByEmail(email).getPassword().equals(password)) {
return true;
}
return false;
}
}


Choose a reason for hiding this comment

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

not fixed

Comment on lines 18 to 24

for (User user: users) {
if (user.getEmail().equals(email)) {
return user;
}
}

Choose a reason for hiding this comment

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

not fixed

@skucherenko7 skucherenko7 requested a review from Rommelua January 10, 2024 10:46
Comment on lines 4 to 5
private final String email;
private final String password;

Choose a reason for hiding this comment

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

Don`t change it

Copy link
Author

Choose a reason for hiding this comment

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

Should I need to remove final? What can I do?

Choose a reason for hiding this comment

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

Yes,
image

Comment on lines 10 to 12
if (userService.findByEmail(email).getPassword().equals(password)) {
return true;
}

Choose a reason for hiding this comment

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

Suggested change
if (userService.findByEmail(email).getPassword().equals(password)) {
return true;
}
if (user.getPassword().equals(password)) {
return true;
}

Choose a reason for hiding this comment

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

You already have a user, you don`t need use "userService.findByEmail(email)" anymore

Choose a reason for hiding this comment

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

After this write the return condition in one line, you don`t need write return 2 times

Choose a reason for hiding this comment

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

nox fixed

@@ -3,18 +3,17 @@
import mate.academy.model.User;

public class UserService {
private static final User[] users = new User[] {
private final User[] users = new User[] {

Choose a reason for hiding this comment

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

Don`t change it

Copy link
Author

Choose a reason for hiding this comment

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

I changed and removed static. What should I do else?

Choose a reason for hiding this comment

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

image
Here is marked as static

Copy link
Author

Choose a reason for hiding this comment

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

I removed static a long time ago. I don't understand why you don't see it

Comment on lines 10 to 12
if (userService.findByEmail(email).getPassword().equals(password)) {
return true;
}

Choose a reason for hiding this comment

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

nox fixed

# Conflicts:
#	src/main/java/mate/academy/service/AuthenticationService.java
Comment on lines 10 to 13
if (user.getPassword().equals(password)) {
return true;
}
return false;

Choose a reason for hiding this comment

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

  1. add check for user != null
  2. inline it

@@ -3,18 +3,17 @@
import mate.academy.model.User;

public class UserService {
private static final User[] users = new User[] {
private final User[] users = new User[] {

Choose a reason for hiding this comment

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

image
Here is marked as static

Comment on lines 4 to 5
private final String email;
private final String password;

Choose a reason for hiding this comment

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

Yes,
image

Comment on lines 10 to 13
if (user != null && user.getPassword().equals(password)) {
return true;
}
return false;

Choose a reason for hiding this comment

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

Here, it looks great, can you simplify it by writing in one line with return? After this you don`t need to write return 2 times) If you need some help better ask it in chat

Choose a reason for hiding this comment

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

not fixed

Copy link

@sokimaaa sokimaaa left a comment

Choose a reason for hiding this comment

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

not fixed prev comments

Comment on lines 10 to 13
if (user != null && user.getPassword().equals(password)) {
return true;
}
return false;

Choose a reason for hiding this comment

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

not fixed

@skucherenko7 skucherenko7 requested a review from sokimaaa January 11, 2024 19:09
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.

5 participants