Skip to content

Commit

Permalink
Merge pull request #42 from CSC207-2022F-UofT/5-feature-1-user-regist…
Browse files Browse the repository at this point in the history
…ration-&-log-in

Feature 1 - User login & registration - Javadoc comments, testing, and other fixes.
  • Loading branch information
celinelumqr authored Nov 22, 2022
2 parents ee74c0e + 6c8798e commit 1d38186
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/login_usecase/LoginPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/login_usecase/LoginRequestModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/login_usecase/LoginResponseModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/logout_usecase/LogoutGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
5 changes: 5 additions & 0 deletions src/main/java/logout_usecase/LogoutInputBoundary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 16 additions & 1 deletion src/main/java/logout_usecase/LogoutInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/logout_usecase/LogoutPresenter.java
Original file line number Diff line number Diff line change
@@ -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);

}
8 changes: 8 additions & 0 deletions src/main/java/logout_usecase/LogoutResponseModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/screens/InMemoryUser.java
Original file line number Diff line number Diff line change
@@ -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<String, UserRegSaveRequest> users = new HashMap<>();

Expand All @@ -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<String, UserRegSaveRequest> getAccounts() {
return users;
}

/**
* @param requestModel the data to save
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,6 +18,12 @@ public class InstructorSaveRequest extends UserRegSaveRequest {

private final ArrayList<String> 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();
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/user_register_usecase/StudentSaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +33,12 @@ public class StudentSaveRequest extends UserRegSaveRequest {

private final ArrayList<LocalTime> 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();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/user_register_usecase/UserRegGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/user_register_usecase/UserRegInputBoundary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
21 changes: 21 additions & 0 deletions src/main/java/user_register_usecase/UserRegInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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;
Expand All @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/main/java/user_register_usecase/UserRegPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/user_register_usecase/UserRegRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/user_register_usecase/UserRegResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/user_register_usecase/UserRegSaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@
// 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;

private String password;

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;
Expand Down

0 comments on commit 1d38186

Please sign in to comment.