Skip to content

Commit 5c3d0fc

Browse files
committed
Implemented UserLoginInteractor2
1 parent 8d3341b commit 5c3d0fc

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/main/java/screens/user_registration_screen/UserRegistrationUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void getUserCredentials(){
8686
}
8787

8888
public static void main(String[] args){
89-
Database testDB = new UserDatabase(new File("newAccounts23"));
89+
Database testDB = new UserDatabase(new File("new"));
9090
UserLoginInteractor2 userLoginInteractor2 = new UserLoginInteractor2(testDB, new UserChatsPresenter());
9191
UserLoginPresenter userLoginPresenter = new UserLoginPresenter(testDB, userLoginInteractor2);
9292
UserVerificationOutputView loginUI = new UserLoginUI(userLoginPresenter);

src/main/java/use_cases/user_login_use_cases/UserLoginInteractor2.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package use_cases.user_login_use_cases;
22

33
import data_access.Database;
4+
import entities.chat.Chat;
45
import entities.user_entities.User;
56

67
import java.util.ArrayList;
8+
import java.util.List;
79

810
public class UserLoginInteractor2 implements UserLoginInputBoundary {
911
private final UserLoginOutputBoundary chatPresenter;
1012
private final Database database;
1113

12-
private User user;
14+
private final List<String> chatsStrings = new ArrayList<>();
1315

1416
public UserLoginInteractor2(Database database, UserLoginOutputBoundary chatPresenter){
1517
this.database = database;
@@ -20,8 +22,19 @@ public UserLoginInteractor2(Database database, UserLoginOutputBoundary chatPrese
2022
public void login(String username, String password) {
2123
//will update this.chatPresenter
2224
//TODO: change below, as its just temporary
23-
user = database.getUser(username);
24-
25+
try {
26+
User user = database.getUser(username);
27+
this.chatPresenter.setPasswordNotMatched(!user.PasswordMatch(password));
28+
this.chatPresenter.setUserNotExists(false);
29+
List<Chat> chats = user.getChats();
30+
for(Chat chat: chats){
31+
this.chatsStrings.add(chat.getName());
32+
}
33+
this.chatPresenter.setChats(this.chatsStrings);
34+
}catch(NullPointerException e){
35+
this.chatPresenter.setUserNotExists(true);
36+
this.chatPresenter.setChats(this.chatsStrings);
37+
}
2538

2639
}
2740

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test_user_login;
2+
3+
public class TestUserLoginInteractor {
4+
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package test_user_login;
2+
3+
public class TestUserLoginPresenter {
4+
}

0 commit comments

Comments
 (0)