diff --git a/src/main/java/login_usecase/LoginPresenter.java b/src/main/java/login_usecase/LoginPresenter.java index 090f943..7e09fd1 100644 --- a/src/main/java/login_usecase/LoginPresenter.java +++ b/src/main/java/login_usecase/LoginPresenter.java @@ -4,6 +4,10 @@ public interface LoginPresenter { + /** + * @param login the login response model + * @return a successful or failure login response model + */ LoginResponseModel prepareSuccessView(LoginResponseModel login); LoginResponseModel prepareFailView(String error) throws LoginFailed; diff --git a/src/main/java/login_usecase/LoginRequestModel.java b/src/main/java/login_usecase/LoginRequestModel.java index d9522bb..b97729f 100644 --- a/src/main/java/login_usecase/LoginRequestModel.java +++ b/src/main/java/login_usecase/LoginRequestModel.java @@ -2,10 +2,17 @@ public class LoginRequestModel { + /** + * A login request that contains the user's input for name and password + */ private String name; private String password; + /** + * @param name the entered username + * @param password the entered password + */ public LoginRequestModel(String name, String password) { this.name = name; this.password = password; diff --git a/src/main/java/login_usecase/LoginResponseModel.java b/src/main/java/login_usecase/LoginResponseModel.java index 8a737b1..eb9d13b 100644 --- a/src/main/java/login_usecase/LoginResponseModel.java +++ b/src/main/java/login_usecase/LoginResponseModel.java @@ -2,10 +2,17 @@ public class LoginResponseModel { + /** + * A login response model with the username and the time of login + */ String name; String loginTime; + /** + * @param username the name of the User that just logged in + * @param timeOfLogin the time at which this User logged in + */ public LoginResponseModel(String username, String timeOfLogin) { this.name = username; this.loginTime = timeOfLogin; diff --git a/src/main/java/logout_usecase/LogoutGateway.java b/src/main/java/logout_usecase/LogoutGateway.java index 6d4d30b..ec48dc7 100644 --- a/src/main/java/logout_usecase/LogoutGateway.java +++ b/src/main/java/logout_usecase/LogoutGateway.java @@ -5,6 +5,11 @@ import java.io.IOException; public interface LogoutGateway { + + /** + * @param requestModel the request to logout + * @throws IOException if something goes wrong while logging out + */ void save(UserRegSaveRequest requestModel) throws IOException; } diff --git a/src/main/java/logout_usecase/LogoutInputBoundary.java b/src/main/java/logout_usecase/LogoutInputBoundary.java index 181df3b..05e0af2 100644 --- a/src/main/java/logout_usecase/LogoutInputBoundary.java +++ b/src/main/java/logout_usecase/LogoutInputBoundary.java @@ -4,5 +4,10 @@ public interface LogoutInputBoundary { + /** + * @param request the request to logout + * @return the logout response + * @throws IOException + */ LogoutResponseModel create(LogoutRequestModel request) throws IOException; } diff --git a/src/main/java/logout_usecase/LogoutInteractor.java b/src/main/java/logout_usecase/LogoutInteractor.java index 511ea09..d2858e3 100644 --- a/src/main/java/logout_usecase/LogoutInteractor.java +++ b/src/main/java/logout_usecase/LogoutInteractor.java @@ -11,19 +11,34 @@ public class LogoutInteractor implements LogoutInputBoundary { + + /** + * The use case for logging out. + */ final LogoutGateway userGateway; final LogoutPresenter userPresenter; final User user; - + /** + * @param gateway the logout gateway (which interacts with the User database) + * @param logoutPresenter the logout presenter + * @param u the User that is logging out + */ public LogoutInteractor(LogoutGateway gateway, LogoutPresenter logoutPresenter, User u) { this.userGateway = gateway; this.userPresenter = logoutPresenter; this.user = u; } + /** + * Save a new UserRegSaveRequest which contains all of the information in the User that is trying to + * log out into the User database. + * @param request the request to logout + * @return the logout response + * @throws IOException + */ @Override public LogoutResponseModel create(LogoutRequestModel request) throws IOException { diff --git a/src/main/java/logout_usecase/LogoutPresenter.java b/src/main/java/logout_usecase/LogoutPresenter.java index 9dadbe6..1da924b 100644 --- a/src/main/java/logout_usecase/LogoutPresenter.java +++ b/src/main/java/logout_usecase/LogoutPresenter.java @@ -1,6 +1,11 @@ package logout_usecase; public interface LogoutPresenter { - LogoutResponseModel prepareSuccessView(LogoutResponseModel login); + + /** + * @param logout the logout response + * @return the successful logout view + */ + LogoutResponseModel prepareSuccessView(LogoutResponseModel logout); } diff --git a/src/main/java/logout_usecase/LogoutResponseModel.java b/src/main/java/logout_usecase/LogoutResponseModel.java index 9d1ae29..e68631f 100644 --- a/src/main/java/logout_usecase/LogoutResponseModel.java +++ b/src/main/java/logout_usecase/LogoutResponseModel.java @@ -2,9 +2,17 @@ public class LogoutResponseModel { + /** + * A response to the user's request to logout + */ String name; String logoutTime; + + /** + * @param name the username + * @param timeOfLogout the time of logout + */ public LogoutResponseModel(String name, String timeOfLogout) { this.name = name; this.logoutTime = timeOfLogout; diff --git a/src/main/java/screens/InMemoryUser.java b/src/main/java/screens/InMemoryUser.java index 6b53553..9836532 100644 --- a/src/main/java/screens/InMemoryUser.java +++ b/src/main/java/screens/InMemoryUser.java @@ -1,12 +1,13 @@ package screens; +import login_usecase.LoginGateway; import user_register_usecase.UserRegSaveRequest; import user_register_usecase.UserRegGateway; import java.util.HashMap; import java.util.Map; -public class InMemoryUser implements UserRegGateway { +public class InMemoryUser implements UserRegGateway, LoginGateway { final private Map users = new HashMap<>(); @@ -20,6 +21,16 @@ public boolean existsByName(String identifier) { return users.containsKey(identifier); } + @Override + public String passOf(String name) { + return users.get(name).getPass(); + } + + @Override + public Map getAccounts() { + return users; + } + /** * @param requestModel the data to save */ diff --git a/src/main/java/user_register_usecase/InstructorSaveRequest.java b/src/main/java/user_register_usecase/InstructorSaveRequest.java index fd6c0bb..db22423 100644 --- a/src/main/java/user_register_usecase/InstructorSaveRequest.java +++ b/src/main/java/user_register_usecase/InstructorSaveRequest.java @@ -6,6 +6,9 @@ import java.util.ArrayList; public class InstructorSaveRequest extends UserRegSaveRequest { + /** + * A transient data storage class that contains the same information as an InstructorUser + */ private String name; @@ -15,6 +18,12 @@ public class InstructorSaveRequest extends UserRegSaveRequest { private final ArrayList courses; + /** + * @param name the name of this Instructor + * @param password the password of this Instructor + * @param instructor the InstructorUser that needs to be saved into this data storage object + * @param creationTime the time at which this InstructorUser was created or last saved + */ public InstructorSaveRequest(String name, String password, InstructorUser instructor, LocalDateTime creationTime) { super(name, password, instructor, creationTime); this.courses = instructor.getCourses(); diff --git a/src/main/java/user_register_usecase/StudentSaveRequest.java b/src/main/java/user_register_usecase/StudentSaveRequest.java index 00214ec..96306a2 100644 --- a/src/main/java/user_register_usecase/StudentSaveRequest.java +++ b/src/main/java/user_register_usecase/StudentSaveRequest.java @@ -9,6 +9,9 @@ import java.util.Map; public class StudentSaveRequest extends UserRegSaveRequest { + /** + * A transient data storage class that contains the same information as a StudentUser + */ private String name; @@ -30,7 +33,12 @@ public class StudentSaveRequest extends UserRegSaveRequest { private final ArrayList workingHours; - + /** + * @param name the name of this StudentUser + * @param password the password of this StudentUser + * @param student the StudentUser that needs to be saved + * @param creationTime the time at which this StudentUser was created or saved + */ public StudentSaveRequest(String name, String password, StudentUser student, LocalDateTime creationTime) { super(name, password, student, creationTime); this.toDoList = student.getToDoList(); diff --git a/src/main/java/user_register_usecase/UserRegGateway.java b/src/main/java/user_register_usecase/UserRegGateway.java index cf560e2..37e7136 100644 --- a/src/main/java/user_register_usecase/UserRegGateway.java +++ b/src/main/java/user_register_usecase/UserRegGateway.java @@ -5,6 +5,11 @@ import java.io.IOException; public interface UserRegGateway { + /** + * The gateway that interacts with the User Database + * @param identifier the username to look for + * @return whether there exists in the User Database a user with username identifier + */ boolean existsByName(String identifier); diff --git a/src/main/java/user_register_usecase/UserRegInputBoundary.java b/src/main/java/user_register_usecase/UserRegInputBoundary.java index da05155..da171eb 100644 --- a/src/main/java/user_register_usecase/UserRegInputBoundary.java +++ b/src/main/java/user_register_usecase/UserRegInputBoundary.java @@ -6,6 +6,11 @@ public interface UserRegInputBoundary { + /** + * @param request the request to register this user + * @return the response to this request to register the user + * @throws IOException + */ UserRegResponse create(UserRegRequest request) throws IOException; } diff --git a/src/main/java/user_register_usecase/UserRegInteractor.java b/src/main/java/user_register_usecase/UserRegInteractor.java index 68fa423..84768b3 100644 --- a/src/main/java/user_register_usecase/UserRegInteractor.java +++ b/src/main/java/user_register_usecase/UserRegInteractor.java @@ -9,18 +9,33 @@ public class UserRegInteractor implements UserRegInputBoundary { + /** + * The use case for registering a user. Responsible for registering a valid new user. + */ + final UserRegGateway userGateway; final UserRegPresenter userPresenter; // private UserFactory userFactory; + private User user; + + /** + * @param gateway the gateway that interacts with the User database + * @param userRegPresenter the presenter that shows the success or failure of this attempt to register + */ public UserRegInteractor(UserRegGateway gateway, UserRegPresenter userRegPresenter) { this.userGateway = gateway; this.userPresenter = userRegPresenter; // this.userFactory = null; } + /** + * @param request the request to register this user + * @return the response to whether this request to register was successful + * @throws IOException + */ @Override public UserRegResponse create(UserRegRequest request) throws IOException { if (userGateway.existsByName(request.getName())) { @@ -43,6 +58,8 @@ public UserRegResponse create(UserRegRequest request) throws IOException { return userPresenter.prepareFailView("Password must be at least 9 characters long"); } + this.user = user; + LocalDateTime now = LocalDateTime.now(); UserRegSaveRequest userModel; @@ -61,4 +78,8 @@ public UserRegResponse create(UserRegRequest request) throws IOException { UserRegResponse accResponseModel = new UserRegResponse(user.getName(), now.toString()); return userPresenter.prepareSuccessView(accResponseModel); } + + public User getUser() { + return this.user; + } } diff --git a/src/main/java/user_register_usecase/UserRegPresenter.java b/src/main/java/user_register_usecase/UserRegPresenter.java index 3b29147..2cd18e4 100644 --- a/src/main/java/user_register_usecase/UserRegPresenter.java +++ b/src/main/java/user_register_usecase/UserRegPresenter.java @@ -4,6 +4,11 @@ public interface UserRegPresenter { + /** The presenter for the user register use case--presents a success or fail view + * @param user the user register response (to the request to register) + * @return a user register response + */ + UserRegResponse prepareSuccessView(UserRegResponse user); UserRegResponse prepareFailView(String error); diff --git a/src/main/java/user_register_usecase/UserRegRequest.java b/src/main/java/user_register_usecase/UserRegRequest.java index 865605b..af8f2d2 100644 --- a/src/main/java/user_register_usecase/UserRegRequest.java +++ b/src/main/java/user_register_usecase/UserRegRequest.java @@ -3,6 +3,9 @@ // Use Case Layer public class UserRegRequest { + /** + * A request to register a new user with this name and password (from user input). + */ private String name; @@ -12,6 +15,12 @@ public class UserRegRequest { private String typeOfUser; + /** + * @param name the name of this User + * @param password the password + * @param reenterPassword the re-entered password + * @param userType the type of User (i.e. Student or Instructor) + */ public UserRegRequest(String name, String password, String reenterPassword, String userType) { this.name = name; this.password = password; diff --git a/src/main/java/user_register_usecase/UserRegResponse.java b/src/main/java/user_register_usecase/UserRegResponse.java index a455520..47d35ad 100644 --- a/src/main/java/user_register_usecase/UserRegResponse.java +++ b/src/main/java/user_register_usecase/UserRegResponse.java @@ -8,6 +8,10 @@ public class UserRegResponse { String creationTime; + /** + * @param login the name of the user that has just logged in + * @param creationTime the time of login + */ public UserRegResponse(String login, String creationTime) { this.login = login; this.creationTime = creationTime; diff --git a/src/main/java/user_register_usecase/UserRegSaveRequest.java b/src/main/java/user_register_usecase/UserRegSaveRequest.java index ab682ca..cc2556c 100644 --- a/src/main/java/user_register_usecase/UserRegSaveRequest.java +++ b/src/main/java/user_register_usecase/UserRegSaveRequest.java @@ -13,6 +13,10 @@ // Use Case Layer public class UserRegSaveRequest implements Serializable { + /** + * A transient data storage class that contains the same information as a User + * The parent to InstructorSaveRequest and StudentSaveRequest + */ private final String name; @@ -20,6 +24,12 @@ public class UserRegSaveRequest implements Serializable { private final LocalDateTime creationTime; + /** + * @param name the name of this User + * @param password the password of this User + * @param user the User object + * @param creationTime the time at which this User was saved + */ public UserRegSaveRequest(String name, String password, User user, LocalDateTime creationTime) { this.name = name; this.password = password;