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

Added solution to method UserService and AuthenticationService #749

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

Conversation

sanmartial
Copy link

No description provided.

@sanmartial sanmartial closed this Oct 23, 2023
@sanmartial sanmartial reopened this Oct 23, 2023
@@ -11,6 +14,12 @@ public class AuthenticationService {
* Return false in any other cases.
*/
public boolean login(String email, String password) {
UserService service = new UserService();

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

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'.
@sanmartial
Copy link
Author

Replaced ref to UserService as a class field;
Removed 'Optional'.

@sanmartial sanmartial closed this Oct 25, 2023
@sanmartial sanmartial reopened this Oct 25, 2023
@sanmartial sanmartial closed this Oct 25, 2023
@sanmartial sanmartial reopened this Oct 25, 2023
Replaced ref to UserService as a class field;
Removed Optional
Comment on lines 21 to 24
if (user != null) {
return user.getPassword().equals(password);
}
return false;

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

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