Skip to content

Commit

Permalink
Implemented UserLoginInteractor2
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhavan7 committed Dec 3, 2022
1 parent 8d3341b commit 5c3d0fc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void getUserCredentials(){
}

public static void main(String[] args){
Database testDB = new UserDatabase(new File("newAccounts23"));
Database testDB = new UserDatabase(new File("new"));
UserLoginInteractor2 userLoginInteractor2 = new UserLoginInteractor2(testDB, new UserChatsPresenter());
UserLoginPresenter userLoginPresenter = new UserLoginPresenter(testDB, userLoginInteractor2);
UserVerificationOutputView loginUI = new UserLoginUI(userLoginPresenter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package use_cases.user_login_use_cases;

import data_access.Database;
import entities.chat.Chat;
import entities.user_entities.User;

import java.util.ArrayList;
import java.util.List;

public class UserLoginInteractor2 implements UserLoginInputBoundary {
private final UserLoginOutputBoundary chatPresenter;
private final Database database;

private User user;
private final List<String> chatsStrings = new ArrayList<>();

public UserLoginInteractor2(Database database, UserLoginOutputBoundary chatPresenter){
this.database = database;
Expand All @@ -20,8 +22,19 @@ public UserLoginInteractor2(Database database, UserLoginOutputBoundary chatPrese
public void login(String username, String password) {
//will update this.chatPresenter
//TODO: change below, as its just temporary
user = database.getUser(username);

try {
User user = database.getUser(username);
this.chatPresenter.setPasswordNotMatched(!user.PasswordMatch(password));
this.chatPresenter.setUserNotExists(false);
List<Chat> chats = user.getChats();
for(Chat chat: chats){
this.chatsStrings.add(chat.getName());
}
this.chatPresenter.setChats(this.chatsStrings);
}catch(NullPointerException e){
this.chatPresenter.setUserNotExists(true);
this.chatPresenter.setChats(this.chatsStrings);
}

}

Expand Down
5 changes: 5 additions & 0 deletions src/test/java/test_user_login/TestUserLoginInteractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test_user_login;

public class TestUserLoginInteractor {

}
4 changes: 4 additions & 0 deletions src/test/java/test_user_login/TestUserLoginPresenter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package test_user_login;

public class TestUserLoginPresenter {
}

0 comments on commit 5c3d0fc

Please sign in to comment.