Skip to content

Commit aa10e64

Browse files
committed
Massive Refactoring, implemented Login Use case according to the MVP pattern
1 parent d07586b commit aa10e64

19 files changed

+242
-74
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package interface_adapters.login_interface_adapters;
2+
3+
import use_cases.user_login_use_cases.UserLoginOutputBoundary;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class UserChatsPresenter implements UserLoginOutputBoundary {
9+
private List<String> chats;
10+
private boolean notExists;
11+
private boolean notMatched;
12+
private String username;
13+
14+
public UserChatsPresenter(){
15+
this.chats = new ArrayList<>();
16+
}
17+
18+
@Override
19+
public void setUsername(String username) {
20+
this.username = username;
21+
}
22+
23+
@Override
24+
public void setChats(List<String> chats) {
25+
this.chats = chats;
26+
}
27+
public List<String> getChats(){
28+
return this.chats;
29+
}
30+
31+
@Override
32+
public void setUserNotExists(boolean notExists) {
33+
this.notExists = notExists;
34+
}
35+
36+
public boolean isNotExists() {
37+
return notExists;
38+
}
39+
40+
@Override
41+
public void setPasswordNotMatched(boolean notMatched) {
42+
this.notMatched = notMatched;
43+
}
44+
45+
@Override
46+
public String getUsername() {
47+
return this.username;
48+
}
49+
50+
public boolean isNotMatched() {
51+
return notMatched;
52+
}
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package interface_adapters.login_interface_adapters;
2+
3+
import data_access.Database;
4+
import use_cases.user_login_use_cases.UserLoginInputBoundary;
5+
6+
public class UserLoginPresenter {
7+
private final UserLoginInputBoundary loginGuard;
8+
private String username;
9+
private String password;
10+
Database database;
11+
private UserLoginViewI loginView;
12+
13+
public UserLoginPresenter(Database database, UserLoginInputBoundary loginGuard){
14+
this.database = database;
15+
this.loginGuard = loginGuard;
16+
}
17+
18+
public void tryLogin() {
19+
loginGuard.login(this.username, this.password);
20+
loginView.setChatsPresenter(loginGuard.getChatsPresenter());
21+
loginView.display();
22+
}
23+
24+
public void setLoginCredentials(String username, String password) {
25+
this.username = username;
26+
this.password = password;
27+
}
28+
public void setLoginView(UserLoginViewI loginView){
29+
this.loginView = loginView;
30+
}
31+
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package interface_adapters.login_interface_adapters;
2+
3+
import use_cases.user_login_use_cases.UserLoginOutputBoundary;
4+
5+
public interface UserLoginViewI {
6+
void display();
7+
void setChatsPresenter(UserLoginOutputBoundary outputBoundary);
8+
}

src/main/java/use_cases/user_registration_use_cases/UserExistsOutputBoundary.java renamed to src/main/java/interface_adapters/user_registration_interface_adapters/UserExistsOutputView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package use_cases.user_registration_use_cases;
1+
package interface_adapters.user_registration_interface_adapters;
22
/**
33
* Presenter interface that presents information, or gets input from user
44
* */
5-
public interface UserExistsOutputBoundary {
5+
public interface UserExistsOutputView {
66
/**
77
* Gets the verification code from the user
88
* */

src/main/java/use_cases/user_registration_use_cases/UserExistsPresenter.java renamed to src/main/java/interface_adapters/user_registration_interface_adapters/UserExistsPresenter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package use_cases.user_registration_use_cases;
1+
package interface_adapters.user_registration_interface_adapters;
22

33
import data_access.Database;
4+
import use_cases.user_registration_use_cases.VerificationCodeDeliveryManager;
5+
import use_cases.user_registration_use_cases.createMailMan;
46

57
/**
68
* This is the class responsible for getting processing the input given by user, and either allowing verification,
@@ -9,9 +11,9 @@
911
public class UserExistsPresenter {
1012
private final VerificationCodeDeliveryManager verCodeDeliveryManager;
1113
Database database;
12-
UserExistsOutputBoundary existsOutputBoundary;
14+
UserExistsOutputView existsOutputBoundary;
1315

14-
public UserExistsPresenter(Database database, UserExistsOutputBoundary existsOutputBoundary, createMailMan mailMan){
16+
public UserExistsPresenter(Database database, UserExistsOutputView existsOutputBoundary, createMailMan mailMan){
1517
this.database = database;
1618
this.existsOutputBoundary = existsOutputBoundary;
1719
//The responsibility of dealing with verification is passed onto this class
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package interface_adapters.user_registration_interface_adapters;
2+
3+
public interface UserVerificationOutputView {
4+
void getLoginCredentials();
5+
void cannotVerify();
6+
7+
}

src/main/java/use_cases/user_registration_use_cases/UserVerificationPresenter.java renamed to src/main/java/interface_adapters/user_registration_interface_adapters/UserVerificationPresenter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package use_cases.user_registration_use_cases;
1+
package interface_adapters.user_registration_interface_adapters;
22

33
import data_access.Database;
44

@@ -8,11 +8,11 @@ public class UserVerificationPresenter {
88
private String password;
99
private String email;
1010

11-
private final UserVerificationOutputBoundary verificationOutputBoundary;
11+
private final UserVerificationOutputView verificationOutputBoundary;
1212

1313
private int code;
1414

15-
public UserVerificationPresenter(Database database, UserVerificationOutputBoundary verificationOutputBoundary){
15+
public UserVerificationPresenter(Database database, UserVerificationOutputView verificationOutputBoundary){
1616
this.database = database;
1717
this.verificationOutputBoundary = verificationOutputBoundary;
1818
}

src/main/java/use_cases/user_registration_use_cases/userRegCredentialsRetriever.java renamed to src/main/java/interface_adapters/user_registration_interface_adapters/userRegCredentialsRetriever.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package use_cases.user_registration_use_cases;
1+
package interface_adapters.user_registration_interface_adapters;
22

33
public interface userRegCredentialsRetriever {
44
void getUserCredentials();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package screens.login_screen;
2+
import interface_adapters.login_interface_adapters.UserLoginViewI;
3+
import screens.appscreen.AppScreen;
4+
import use_cases.user_login_use_cases.UserLoginOutputBoundary;
5+
6+
import java.util.ArrayList;
7+
8+
public class AppScreenCreator implements UserLoginViewI {
9+
private String username ;
10+
private ArrayList<String> chats;
11+
private boolean userNotExists;
12+
private boolean passNotMatched;
13+
AppScreen appScreen;
14+
public AppScreenCreator(){
15+
}
16+
@Override
17+
public void display() {
18+
if(userNotExists|| passNotMatched){
19+
showUnableToLogin();
20+
}else{
21+
/*this.appScreen = new AppScreen(username, chats);*/
22+
System.out.println(username);
23+
}
24+
}
25+
26+
private void showUnableToLogin() {
27+
System.out.println("unable to login");
28+
}
29+
@Override
30+
public void setChatsPresenter(UserLoginOutputBoundary chatsPresenter){
31+
this.username = chatsPresenter.getUsername();
32+
this.chats = (ArrayList<String>) chatsPresenter.getChats();
33+
this.userNotExists = chatsPresenter.isNotExists();
34+
this.passNotMatched = chatsPresenter.isNotMatched();
35+
}
36+
37+
}

src/main/java/screens/login_screen/UserLoginUI.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
package screens.login_screen;
2-
import use_cases.user_login_use_cases.UserLoginPresenter;
3-
import use_cases.user_registration_use_cases.UserVerificationOutputBoundary;
2+
import data_access.Database;
3+
import data_access.UserDatabase;
4+
import interface_adapters.login_interface_adapters.UserChatsPresenter;
5+
import interface_adapters.login_interface_adapters.UserLoginViewI;
6+
import use_cases.user_login_use_cases.UserLoginInputBoundary;
7+
import interface_adapters.login_interface_adapters.UserLoginPresenter;
8+
import use_cases.user_login_use_cases.UserLoginInteractor2;
9+
import interface_adapters.user_registration_interface_adapters.UserVerificationOutputView;
410

511
import javax.swing.*;
612
import java.awt.event.ActionEvent;
713
import java.awt.event.ActionListener;
14+
import java.io.File;
815

916
/** This is the screen on which the user enters his credentials in order to login **/
10-
public class UserLoginUI implements ActionListener, UserVerificationOutputBoundary {
17+
public class UserLoginUI implements ActionListener, UserVerificationOutputView {
1118

12-
private final UserLoginPresenter loginInteractor;
19+
private final UserLoginPresenter loginPresenter;
1320
JTextField credentialText;
1421
JPasswordField passwordText;
1522

16-
public UserLoginUI(UserLoginPresenter loginInteractor){
17-
this.loginInteractor = loginInteractor;
23+
public UserLoginUI(UserLoginPresenter loginPresenter){
24+
UserLoginViewI loginViewI = new AppScreenCreator();
25+
this.loginPresenter = loginPresenter;
26+
this.loginPresenter.setLoginView(loginViewI);
27+
}
28+
//For Testing Purposes
29+
public static void main(String[] args){
30+
Database userDB = new UserDatabase(new File("new"));
31+
UserLoginInputBoundary inputBoundary = new UserLoginInteractor2(userDB, new UserChatsPresenter());
32+
UserLoginPresenter loginPresenter1 = new UserLoginPresenter(userDB, inputBoundary);
33+
UserLoginUI loginUI = new UserLoginUI(loginPresenter1);
34+
loginUI.getLoginCredentials();
1835
}
1936
@Override
2037
public void getLoginCredentials(){
@@ -69,7 +86,7 @@ public void cannotVerify() {
6986
public void actionPerformed(ActionEvent e) {
7087
String username = credentialText.getText();
7188
String password = passwordText.getText();
72-
loginInteractor.setLoginCredentials(username, password);
73-
loginInteractor.tryLogin();
89+
loginPresenter.setLoginCredentials(username, password);
90+
loginPresenter.tryLogin();
7491
}
7592
}

0 commit comments

Comments
 (0)