Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static void main(String[] args) {
.addLoggedInView()
.addSignupUseCase()
.addLoginUseCase()
.addLogoutUseCase()
.addChangePasswordUseCase()
.build();

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/interface_adapter/logout/LogoutController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import use_case.logout.LogoutInputBoundary;


/**
* The controller for the Logout Use Case.
*/
Expand All @@ -10,13 +11,14 @@ public class LogoutController {
private LogoutInputBoundary logoutUseCaseInteractor;

public LogoutController(LogoutInputBoundary logoutUseCaseInteractor) {
// TODO: Save the interactor in the instance variable.
this.logoutUseCaseInteractor = logoutUseCaseInteractor;
}

/**
* Executes the Logout Use Case.
*/
public void execute() {
// TODO: run the use case interactor for the logout use case
logoutUseCaseInteractor.execute();

}
}
}
14 changes: 11 additions & 3 deletions src/main/java/interface_adapter/logout/LogoutPresenter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package interface_adapter.logout;

import interface_adapter.ViewManagerModel;
import interface_adapter.logged_in.LoggedInState;
import interface_adapter.logged_in.LoggedInViewModel;
import interface_adapter.login.LoginState;
import interface_adapter.login.LoginViewModel;
import use_case.logout.LogoutOutputBoundary;
import use_case.logout.LogoutOutputData;
Expand All @@ -18,7 +20,9 @@ public class LogoutPresenter implements LogoutOutputBoundary {
public LogoutPresenter(ViewManagerModel viewManagerModel,
LoggedInViewModel loggedInViewModel,
LoginViewModel loginViewModel) {
// TODO: assign to the three instance variables.
this.viewManagerModel = viewManagerModel;
this.loggedInViewModel = loggedInViewModel;
this.loginViewModel = loginViewModel;
}

@Override
Expand All @@ -29,15 +33,19 @@ public void prepareSuccessView(LogoutOutputData response) {
// We also need to set the username in the LoggedInState to
// the empty string.

// TODO: have prepareSuccessView update the LoggedInState
// 1. get the LoggedInState out of the appropriate View Model,
// 2. set the username in the state to the empty string
// 3. firePropertyChanged so that the View that is listening is updated.
final LoggedInState loggedInState = loggedInViewModel.getState();
loggedInState.setUsername("");
loggedInViewModel.firePropertyChange();

// TODO: have prepareSuccessView update the LoginState
// 1. get the LoginState out of the appropriate View Model,
// 2. set the username in the state to be the username of the user that just logged out,
// 3. firePropertyChanged so that the View that is listening is updated.
final LoginState loginState = loginViewModel.getState();
loginState.setUsername(response.getUsername());
loginViewModel.firePropertyChange();

// This code tells the View Manager to switch to the LoginView.
this.viewManagerModel.setState(loginViewModel.getViewName());
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/use_case/logout/LogoutInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ public class LogoutInteractor implements LogoutInputBoundary {

public LogoutInteractor(LogoutUserDataAccessInterface userDataAccessInterface,
LogoutOutputBoundary logoutOutputBoundary) {
// TODO: save the DAO and Presenter in the instance variables.
this.userDataAccessObject = userDataAccessInterface;
this.logoutPresenter = logoutOutputBoundary;
}

@Override
public void execute() {
// TODO: implement the logic of the Logout Use Case
// * set the current username to null in the DAO
// * instantiate the `LogoutOutputData`, which needs to contain the username.
// * tell the presenter to prepare a success view.
String username = userDataAccessObject.getCurrentUsername();
userDataAccessObject.setCurrentUsername(null);
LogoutOutputData outputData = new LogoutOutputData(username);
logoutPresenter.prepareSuccessView(outputData);
}
}

9 changes: 6 additions & 3 deletions src/main/java/view/LoggedInView.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ public void changedUpdate(DocumentEvent e) {
* @param evt the ActionEvent to react to
*/
public void actionPerformed(ActionEvent evt) {
// TODO: execute the logout use case through the Controller
System.out.println("Click " + evt.getActionCommand());
if (evt.getSource() == logOut) {
if (logoutController != null) {
logoutController.execute();
}
}
}

@Override
Expand Down Expand Up @@ -140,6 +143,6 @@ public void setChangePasswordController(ChangePasswordController changePasswordC
}

public void setLogoutController(LogoutController logoutController) {
// TODO: save the logout controller in the instance variable.
this.logoutController = logoutController;
}
}