diff --git a/README.md b/README.md index 9487008b..d6d2e3c5 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ The TODOs are summarized below (by file) to help your team decide how to split t --- - `Main.java` (tip: look at how other use cases have been added) - -[ ] TODO: add the logout use case to the app + -[X] TODO: add the logout use case to the app --- @@ -116,8 +116,8 @@ The TODOs are summarized below (by file) to help your team decide how to split t --- - `LogoutInteractor.java` (tip: refer to `ChangePasswordInteractor.java` for similar code) - -[ ] TODO: save the DAO and Presenter in the instance variables. - -[ ] TODO: implement the logic of the Logout Use Case + -[X] TODO: save the DAO and Presenter in the instance variables. + -[X] TODO: implement the logic of the Logout Use Case > Note: there is no input data necessary for this use case. diff --git a/src/main/java/app/Main.java b/src/main/java/app/Main.java index 424404fb..371338cd 100644 --- a/src/main/java/app/Main.java +++ b/src/main/java/app/Main.java @@ -12,6 +12,7 @@ public static void main(String[] args) { .addSignupUseCase() .addLoginUseCase() .addChangePasswordUseCase() + .addLogoutUseCase() .build(); application.pack(); diff --git a/src/main/java/interface_adapter/logout/LogoutController.java b/src/main/java/interface_adapter/logout/LogoutController.java index 49eedf89..bdaa262d 100644 --- a/src/main/java/interface_adapter/logout/LogoutController.java +++ b/src/main/java/interface_adapter/logout/LogoutController.java @@ -1,16 +1,21 @@ package interface_adapter.logout; +import use_case.login.LoginInputData; import use_case.logout.LogoutInputBoundary; +import use_case.logout.LogoutInteractor; +import use_case.logout.LogoutOutputData; /** * The controller for the Logout Use Case. */ public class LogoutController { - private LogoutInputBoundary logoutUseCaseInteractor; + private final LogoutInputBoundary logoutUseCaseInteractor; public LogoutController(LogoutInputBoundary logoutUseCaseInteractor) { // TODO: Save the interactor in the instance variable. + this.logoutUseCaseInteractor = logoutUseCaseInteractor; + } /** @@ -18,5 +23,6 @@ public LogoutController(LogoutInputBoundary logoutUseCaseInteractor) { */ public void execute() { // TODO: run the use case interactor for the logout use case + logoutUseCaseInteractor.execute(); } } diff --git a/src/main/java/use_case/logout/LogoutInteractor.java b/src/main/java/use_case/logout/LogoutInteractor.java index d252f7c4..aee8f683 100644 --- a/src/main/java/use_case/logout/LogoutInteractor.java +++ b/src/main/java/use_case/logout/LogoutInteractor.java @@ -4,20 +4,24 @@ * The Logout Interactor. */ public class LogoutInteractor implements LogoutInputBoundary { - private LogoutUserDataAccessInterface userDataAccessObject; - private LogoutOutputBoundary logoutPresenter; + private final LogoutUserDataAccessInterface userDataAccessObject; + private final LogoutOutputBoundary logoutPresenter; 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. + final String username = userDataAccessObject.getCurrentUsername(); + userDataAccessObject.setCurrentUsername(null); + final LogoutOutputData logoutOutputData = new LogoutOutputData(username); + logoutPresenter.prepareSuccessView(logoutOutputData); } }