From 0e5d20a68b0a5b2c0072a681dd0b33e13930b24e Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Mon, 28 Nov 2022 14:03:12 -0500 Subject: [PATCH 01/20] Deleted InstructorUserFactory and StudentUserFactor as per feedback from TA and added an initializeUser method to the UserRegSaveRequest class (both StudentSaveRequest and InstructorSaveRequest implement it) --- .../java/Entities/GeneralUserFactory.java | 23 +++++++++++++++++++ .../java/entities/InstructorUserFactory.java | 18 --------------- .../java/entities/StudentUserFactory.java | 17 -------------- src/main/java/entities/UserFactory.java | 4 +++- .../java/login_usecase/LoginInteractor.java | 23 ++----------------- .../java/logout_usecase/LogoutInteractor.java | 1 + .../InstructorSaveRequest.java | 7 ++++++ .../StudentSaveRequest.java | 14 +++++++++++ .../UserRegInteractor.java | 17 ++++++-------- .../UserRegSaveRequest.java | 4 ++++ 10 files changed, 61 insertions(+), 67 deletions(-) create mode 100644 src/main/java/Entities/GeneralUserFactory.java delete mode 100644 src/main/java/entities/InstructorUserFactory.java delete mode 100644 src/main/java/entities/StudentUserFactory.java diff --git a/src/main/java/Entities/GeneralUserFactory.java b/src/main/java/Entities/GeneralUserFactory.java new file mode 100644 index 0000000..0b19100 --- /dev/null +++ b/src/main/java/Entities/GeneralUserFactory.java @@ -0,0 +1,23 @@ +package entities; + +// Entity Layer + +public class GeneralUserFactory implements UserFactory { + + /** + * @param name the name of this StudentUser + * @param password the password of this StudentUser + * @return a new StudentUser + */ + + @Override + public StudentUser createStudent(String name, String password) { + return new StudentUser(name, password); + } + + @Override + public InstructorUser createInstructor(String name, String password) { + return new InstructorUser(name, password); + } + +} diff --git a/src/main/java/entities/InstructorUserFactory.java b/src/main/java/entities/InstructorUserFactory.java deleted file mode 100644 index a5f01d5..0000000 --- a/src/main/java/entities/InstructorUserFactory.java +++ /dev/null @@ -1,18 +0,0 @@ -package entities; - -// Entity layer - -public class InstructorUserFactory implements UserFactory { - - /** - * @param name the name of this InstructorUser - * @param password the password of this InstructorUser's account - * @return a new InstructorUser - */ - - @Override - public User create(String name, String password) { - return new InstructorUser(name, password); - } - -} diff --git a/src/main/java/entities/StudentUserFactory.java b/src/main/java/entities/StudentUserFactory.java deleted file mode 100644 index f99d65a..0000000 --- a/src/main/java/entities/StudentUserFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package entities; - -// Entity Layer - -public class StudentUserFactory implements UserFactory { - - /** - * @param name the name of this StudentUser - * @param password the password of this StudentUser - * @return a new StudentUser - */ - @Override - public User create(String name, String password) { - return new StudentUser(name, password); - } - -} diff --git a/src/main/java/entities/UserFactory.java b/src/main/java/entities/UserFactory.java index df97992..2ec53e4 100644 --- a/src/main/java/entities/UserFactory.java +++ b/src/main/java/entities/UserFactory.java @@ -7,5 +7,7 @@ public interface UserFactory { /** * Creates Users with the specified name and password */ - User create(String name, String password); + StudentUser createStudent(String name, String password); + + InstructorUser createInstructor(String name, String password); } diff --git a/src/main/java/login_usecase/LoginInteractor.java b/src/main/java/login_usecase/LoginInteractor.java index 62ff85b..0bc22c2 100644 --- a/src/main/java/login_usecase/LoginInteractor.java +++ b/src/main/java/login_usecase/LoginInteractor.java @@ -1,15 +1,10 @@ package login_usecase; -import entities.InstructorUser; -import entities.StudentUser; import entities.User; import screens.LoginFailed; -import user_register_usecase.InstructorSaveRequest; -import user_register_usecase.StudentSaveRequest; import user_register_usecase.UserRegSaveRequest; import java.time.LocalDateTime; -import java.util.HashMap; public class LoginInteractor implements LoginInputBoundary { @@ -35,7 +30,7 @@ public LoginInteractor(LoginGateway loginGate, LoginPresenter loginPres) { * * @param requestModel the Login request (containing the user's input) * @return the response to this login request (whether it worked or not) - * @throws LoginFailed + * @throws LoginFailed if the username doesn't exist or the password is incorrect */ @Override public LoginResponseModel create(LoginRequestModel requestModel) throws LoginFailed { @@ -57,20 +52,6 @@ private User createUser(LoginRequestModel requestModel) { // creating a new User object using the information in the UserRegSaveRequest UserRegSaveRequest userSave = loginGateway.getAccounts().get(requestModel.getName()); - User user; - if (userSave instanceof InstructorSaveRequest) { - user = new InstructorUser(userSave.getName(), userSave.getPass()); - ((InstructorUser) user).setCourses(((InstructorSaveRequest) userSave).getCourses()); - } else { - user = new StudentUser(userSave.getName(), userSave.getPass()); - ((StudentUser) user).setCourses(((StudentSaveRequest) userSave).getCourses()); - ((StudentUser) user).setToDoList(((StudentSaveRequest) userSave).getCourses()); - ((StudentUser) user).setTaskArchive(((StudentSaveRequest) userSave).getTaskArchive()); - ((StudentUser) user).setInbox(((StudentSaveRequest) userSave).getInbox()); - ((StudentUser) user).setNotifications(((StudentSaveRequest) userSave).getNotifications()); - ((StudentUser) user).setDesiredGrades(((StudentSaveRequest) userSave).getDesiredGrades()); - ((StudentUser) user).setWorkingHours(((StudentSaveRequest) userSave).getWorkingHours()); - } - return user; + return userSave.initializeUser(); } } diff --git a/src/main/java/logout_usecase/LogoutInteractor.java b/src/main/java/logout_usecase/LogoutInteractor.java index d2858e3..813d35d 100644 --- a/src/main/java/logout_usecase/LogoutInteractor.java +++ b/src/main/java/logout_usecase/LogoutInteractor.java @@ -45,6 +45,7 @@ public LogoutResponseModel create(LogoutRequestModel request) throws IOException LocalDateTime now = LocalDateTime.now(); UserRegSaveRequest userModel; + if (user instanceof StudentUser) { userModel = new StudentSaveRequest(user.getName(), user.getPass(), (StudentUser) user, now); diff --git a/src/main/java/user_register_usecase/InstructorSaveRequest.java b/src/main/java/user_register_usecase/InstructorSaveRequest.java index db22423..0f207b7 100644 --- a/src/main/java/user_register_usecase/InstructorSaveRequest.java +++ b/src/main/java/user_register_usecase/InstructorSaveRequest.java @@ -33,4 +33,11 @@ public ArrayList getCourses() { return this.courses; } + @Override + public InstructorUser initializeUser() { + InstructorUser i = new InstructorUser(this.name, this.password); + i.setCourses(this.courses); + return i; + } + } diff --git a/src/main/java/user_register_usecase/StudentSaveRequest.java b/src/main/java/user_register_usecase/StudentSaveRequest.java index 96306a2..e58bd87 100644 --- a/src/main/java/user_register_usecase/StudentSaveRequest.java +++ b/src/main/java/user_register_usecase/StudentSaveRequest.java @@ -1,5 +1,6 @@ package user_register_usecase; +import entities.InstructorUser; import entities.StudentUser; import java.time.LocalDateTime; @@ -84,4 +85,17 @@ public ArrayList getWorkingHours() { return this.workingHours; } + @Override + public StudentUser initializeUser() { + StudentUser s = new StudentUser(this.name, this.password); + s.setCourses(this.courses); + s.setToDoList(this.toDoList); + s.setTaskArchive(this.getTaskArchive()); + s.setInbox(this.getInbox()); + s.setNotifications(this.getNotifications()); + s.setDesiredGrades(this.getDesiredGrades()); + s.setWorkingHours(this.getWorkingHours()); + return s; + } + } diff --git a/src/main/java/user_register_usecase/UserRegInteractor.java b/src/main/java/user_register_usecase/UserRegInteractor.java index 84768b3..d7c1a15 100644 --- a/src/main/java/user_register_usecase/UserRegInteractor.java +++ b/src/main/java/user_register_usecase/UserRegInteractor.java @@ -17,24 +17,25 @@ public class UserRegInteractor implements UserRegInputBoundary { final UserRegPresenter userPresenter; -// private UserFactory userFactory; + final 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 + * @param factory the factory that creates Users */ - public UserRegInteractor(UserRegGateway gateway, UserRegPresenter userRegPresenter) { + public UserRegInteractor(UserRegGateway gateway, UserRegPresenter userRegPresenter, UserFactory factory) { this.userGateway = gateway; this.userPresenter = userRegPresenter; -// this.userFactory = null; + this.userFactory = factory; } /** * @param request the request to register this user * @return the response to whether this request to register was successful - * @throws IOException + * @throws IOException if anything goes wrong */ @Override public UserRegResponse create(UserRegRequest request) throws IOException { @@ -46,20 +47,16 @@ public UserRegResponse create(UserRegRequest request) throws IOException { return userPresenter.prepareFailView("Enter either 'Instructor' or 'Student'."); } - UserFactory userFactory; if (request.getTypeOfUser().equals("Instructor")) { - userFactory = new InstructorUserFactory(); + this.user = userFactory.createInstructor(request.getName(), request.getPassword()); } else { - userFactory = new StudentUserFactory(); + this.user = userFactory.createStudent(request.getName(), request.getPassword()); } - User user = userFactory.create(request.getName(), request.getPassword()); if (!user.checkPassword()) { return userPresenter.prepareFailView("Password must be at least 9 characters long"); } - this.user = user; - LocalDateTime now = LocalDateTime.now(); UserRegSaveRequest userModel; diff --git a/src/main/java/user_register_usecase/UserRegSaveRequest.java b/src/main/java/user_register_usecase/UserRegSaveRequest.java index cc2556c..905ce2a 100644 --- a/src/main/java/user_register_usecase/UserRegSaveRequest.java +++ b/src/main/java/user_register_usecase/UserRegSaveRequest.java @@ -48,4 +48,8 @@ public LocalDateTime getCreationTime() { return creationTime; } + public User initializeUser() { + return null; + } + } From 22585827fb8cf0aeba4edb08d66bb7317fe21893 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Tue, 29 Nov 2022 10:55:34 -0500 Subject: [PATCH 02/20] Made some changes to the implementation of FileUser and now my main and data persistence is working (but haven't tested so don't get too excited) --- src/main/java/screens/FileUser.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/screens/FileUser.java b/src/main/java/screens/FileUser.java index 180faf1..325e67d 100644 --- a/src/main/java/screens/FileUser.java +++ b/src/main/java/screens/FileUser.java @@ -6,6 +6,8 @@ import user_register_usecase.UserRegSaveRequest; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.security.KeyException; import java.time.LocalDateTime; import java.util.HashMap; @@ -25,7 +27,19 @@ public FileUser(String path) throws IOException, ClassNotFoundException { */ this.filePath = path; - this.accounts = readFile(); + + // method that checks if a path or file exists or not and then + // writes an empty map to a new file if it doesn't exist + // and reads the existing file if it does exist + + if (Files.exists(Path.of(path))) { + this.accounts = readFile(); + } else { + this.accounts = new HashMap(); + save(); + } + + } private HashMap readFile() throws IOException, ClassNotFoundException { @@ -49,7 +63,7 @@ public void save(UserRegSaveRequest requestModel) throws IOException { private void save() throws IOException { /* - * Write the new map of usernames to UserRegSaveRequest objects into the User database file. + * Write the map of usernames to UserRegSaveRequest objects into the User database file. */ FileOutputStream fileWriter = new FileOutputStream(filePath); From f0b1f42316bfe25a4737f3a984d2c964c7c941b2 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Wed, 30 Nov 2022 16:40:01 -0500 Subject: [PATCH 03/20] Some changes to UserFactory based on TA feedback --- src/main/java/entities/UserFactory.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/entities/UserFactory.java b/src/main/java/entities/UserFactory.java index 2ec53e4..8b13789 100644 --- a/src/main/java/entities/UserFactory.java +++ b/src/main/java/entities/UserFactory.java @@ -1,13 +1 @@ -package entities; - -// Entity Layer - -public interface UserFactory { - /** - * Creates Users with the specified name and password - */ - StudentUser createStudent(String name, String password); - - InstructorUser createInstructor(String name, String password); -} From a8dac0fbbded84a751e8488808449bf1dc6cde6d Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Wed, 30 Nov 2022 16:45:05 -0500 Subject: [PATCH 04/20] Update UserFactory.java --- src/main/java/Entities/UserFactory.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/Entities/UserFactory.java b/src/main/java/Entities/UserFactory.java index 8b13789..2ec53e4 100644 --- a/src/main/java/Entities/UserFactory.java +++ b/src/main/java/Entities/UserFactory.java @@ -1 +1,13 @@ +package entities; + +// Entity Layer + +public interface UserFactory { + /** + * Creates Users with the specified name and password + */ + StudentUser createStudent(String name, String password); + + InstructorUser createInstructor(String name, String password); +} From e923f3e9d11b986476a3935cbc3e7beb070631ab Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Wed, 30 Nov 2022 17:20:44 -0500 Subject: [PATCH 05/20] merging --- src/main/java/entities/UserFactory.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/entities/UserFactory.java b/src/main/java/entities/UserFactory.java index 8b13789..2ec53e4 100644 --- a/src/main/java/entities/UserFactory.java +++ b/src/main/java/entities/UserFactory.java @@ -1 +1,13 @@ +package entities; + +// Entity Layer + +public interface UserFactory { + /** + * Creates Users with the specified name and password + */ + StudentUser createStudent(String name, String password); + + InstructorUser createInstructor(String name, String password); +} From 0353ab6601fb5d4f1dad6366643991aae3044303 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Wed, 30 Nov 2022 18:00:11 -0500 Subject: [PATCH 06/20] Made some changes after pulling changes from main --- src/main/java/Main.java | 7 ++++--- .../java/screens/login_registration/FileUser.java | 14 +++++--------- .../login_usecase/LoginInteractor.java | 7 ++++--- .../login_usecase/LoginRequestModel.java | 4 ++-- .../user_register_usecase/UserRegInteractor.java | 15 ++++++++++----- .../user_register_usecase/UserRegSaveRequest.java | 1 - 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e506a76..a18e7db 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -21,7 +21,7 @@ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws IOException, ClassNotFoundException { // Build the main program window JFrame application = new JFrame("32 Things To Do"); @@ -35,9 +35,10 @@ public static void main(String[] args) { HashMap allCourses = new HashMap<>(); // Create the components for injection into the use cases - UserRegGateway regUser = new InMemoryUser(); + UserRegGateway regUser = new FileUser("users.ser"); + UserFactory fac = new GeneralUserFactory(); UserRegPresenter userPresenter = new UserRegResponseFormatter(); - UserRegInputBoundary userInteractor = new UserRegInteractor(regUser, userPresenter); + UserRegInputBoundary userInteractor = new UserRegInteractor(regUser, userPresenter, fac); UserRegController userRegisterController = new UserRegController(userInteractor); User user = ((UserRegInteractor) userInteractor).getUser(); diff --git a/src/main/java/screens/login_registration/FileUser.java b/src/main/java/screens/login_registration/FileUser.java index 325e67d..9808b90 100644 --- a/src/main/java/screens/login_registration/FileUser.java +++ b/src/main/java/screens/login_registration/FileUser.java @@ -1,17 +1,13 @@ -package screens; - -import login_usecase.LoginGateway; -import logout_usecase.LogoutGateway; -import user_register_usecase.UserRegGateway; -import user_register_usecase.UserRegSaveRequest; +package screens.login_registration; +import use_cases.login_registration.login_usecase.LoginGateway; +import use_cases.login_registration.logout_usecase.LogoutGateway; +import use_cases.login_registration.user_register_usecase.UserRegGateway; +import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; -import java.security.KeyException; -import java.time.LocalDateTime; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway { diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java b/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java index 0bc22c2..18e54d4 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java @@ -1,8 +1,9 @@ -package login_usecase; +package use_cases.login_registration.login_usecase; import entities.User; -import screens.LoginFailed; -import user_register_usecase.UserRegSaveRequest; +import screens.login_registration.LoginFailed; +import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; + import java.time.LocalDateTime; diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java b/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java index 4f1068a..8a3542a 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java @@ -18,11 +18,11 @@ public LoginRequestModel(String name, String password) { this.password = password; } - String getName() { return name; } + public String getName() { return name; } void setName(String name) { this.name = name; } - String getPass() { return password; } + public String getPass() { return password; } void setPass(String pass) { this.password = pass; diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java index 2dd3e97..82b3513 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java @@ -59,6 +59,15 @@ public UserRegResponse create(UserRegRequest request) throws IOException { LocalDateTime now = LocalDateTime.now(); + UserRegSaveRequest userModel = getUserRegSaveRequest(now); + + userGateway.save(userModel); + + UserRegResponse accResponseModel = new UserRegResponse(user.getName(), now.toString()); + return userPresenter.prepareSuccessView(accResponseModel); + } + + private UserRegSaveRequest getUserRegSaveRequest(LocalDateTime now) { UserRegSaveRequest userModel; if (user instanceof StudentUser) { userModel = new StudentSaveRequest(user.getName(), user.getPass(), @@ -69,11 +78,7 @@ public UserRegResponse create(UserRegRequest request) throws IOException { } else { userModel = new UserRegSaveRequest(user.getName(), user.getPass(), user, now); } - - userGateway.save(userModel); - - UserRegResponse accResponseModel = new UserRegResponse(user.getName(), now.toString()); - return userPresenter.prepareSuccessView(accResponseModel); + return userModel; } public User getUser() { diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java index a488b65..f70f223 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java @@ -1,7 +1,6 @@ package use_cases.login_registration.user_register_usecase; import entities.InstructorUser; -import entities.StudentUser; import entities.User; import java.io.Serializable; From 3423ccb3f606e3d0a4b95b45356708d4ef809e5c Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Wed, 30 Nov 2022 19:10:09 -0500 Subject: [PATCH 07/20] more minor changes after pulling from main --- src/main/java/data/courses.csv | 1 + src/test/java/FileUserTest.java | 1 - users.ser | Bin 0 -> 937 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 src/main/java/data/courses.csv create mode 100644 users.ser diff --git a/src/main/java/data/courses.csv b/src/main/java/data/courses.csv new file mode 100644 index 0000000..122444c --- /dev/null +++ b/src/main/java/data/courses.csv @@ -0,0 +1 @@ +course_name,course_instructor,tasks? diff --git a/src/test/java/FileUserTest.java b/src/test/java/FileUserTest.java index 9f76778..45eea34 100644 --- a/src/test/java/FileUserTest.java +++ b/src/test/java/FileUserTest.java @@ -1,5 +1,4 @@ import org.junit.jupiter.api.Test; -//import screens.FileUser2; public class FileUserTest { diff --git a/users.ser b/users.ser new file mode 100644 index 0000000000000000000000000000000000000000..9747cc969550703fb3c91c91d9f6e9442cf63bbb GIT binary patch literal 937 zcmcIiziSjh6n@_AvboEhdhr)Qw6L+;Llb|ILId%M>o?v zcDtyetC-r(mp8-1w?0;((t&y`FzBGKgTajzRx^GJZ*e9kDnTMW$M;^-(jexsyk_A3hh&9Nf{2Q8ixbKkCeX0l4T2 A`Tzg` literal 0 HcmV?d00001 From 3dded37162714b8cd8bd929ae622ca352be98cf6 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 13:04:14 -0500 Subject: [PATCH 08/20] trying to figure out what is the issue with my checks --- src/test/java/entities/UserUnitTest.java | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/java/entities/UserUnitTest.java diff --git a/src/test/java/entities/UserUnitTest.java b/src/test/java/entities/UserUnitTest.java new file mode 100644 index 0000000..ba0bb16 --- /dev/null +++ b/src/test/java/entities/UserUnitTest.java @@ -0,0 +1,51 @@ +package entities; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UserUnitTest { + + @Test + void testShortPassStudent() { + User user = new StudentUser("Rex", "7567"); + + assertFalse(user.checkPassword()); + } + + @Test + void testShortPassInstructor() { + User user = new InstructorUser("Cody", "2224"); + + assertFalse(user.checkPassword()); + } + + @Test + void testGoodPassStudent() { + User user = new StudentUser("Ahsoka", "123456789"); + + assertTrue(user.checkPassword()); + } + + @Test + void testGoodPassInstructor() { + User user = new InstructorUser("Anakin", "123456789"); + + assertTrue(user.checkPassword()); + } + + @Test + void testNoPassInstructor() { + User user = new InstructorUser("Jesse", ""); + + assertFalse(user.checkPassword()); + } + + @Test + void testNoPassStudent() { + User user = new StudentUser("Cody", ""); + + assertFalse(user.checkPassword()); + } +} From 8930bccb0313f6dc2562ec0579e4a7e3cc7978dc Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 14:56:05 -0500 Subject: [PATCH 09/20] added some tests --- .../UserRegInteractor.java | 18 ++++ src/test/java/entities/UserFactoryTest.java | 36 +++++++ .../UserRegInteractorTest.java | 95 +++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 src/test/java/entities/UserFactoryTest.java create mode 100644 src/test/java/user_register_usecase/UserRegInteractorTest.java diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java index 82b3513..68c1fbf 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java @@ -81,6 +81,24 @@ private UserRegSaveRequest getUserRegSaveRequest(LocalDateTime now) { return userModel; } + /** + * For testing purposes only!! Do not actually use. + * @param now time of creation + */ + public UserRegSaveRequest getUserSaveRequest(LocalDateTime now) { + UserRegSaveRequest userModel; + if (user instanceof StudentUser) { + userModel = new StudentSaveRequest(user.getName(), user.getPass(), + (StudentUser) user, now); + } else if (user instanceof InstructorUser) { + userModel = new InstructorSaveRequest(user.getName(), user.getPass(), + (InstructorUser) user, now); + } else { + userModel = new UserRegSaveRequest(user.getName(), user.getPass(), user, now); + } + return userModel; + } + public User getUser() { return this.user; } diff --git a/src/test/java/entities/UserFactoryTest.java b/src/test/java/entities/UserFactoryTest.java new file mode 100644 index 0000000..358318a --- /dev/null +++ b/src/test/java/entities/UserFactoryTest.java @@ -0,0 +1,36 @@ +package entities; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class UserFactoryTest { + + @Test + void testCreateStudentGoodPass() { + GeneralUserFactory g = new GeneralUserFactory(); + StudentUser s = g.createStudent("Fives", "123456789"); + // doing this because if it wasn't a StudentUser, it wouldn't compile + Assertions.assertTrue(s.checkPassword()); + } + + @Test + void testCreateInstructorGoodPass() { + GeneralUserFactory g = new GeneralUserFactory(); + InstructorUser s = g.createInstructor("Hardcase", "123456789"); + Assertions.assertTrue(s.checkPassword()); + } + + @Test + void testCreateStudentBadPass() { + GeneralUserFactory g = new GeneralUserFactory(); + StudentUser s = g.createStudent("Vaughn", "2468"); + Assertions.assertFalse(s.checkPassword()); + } + + @Test + void testCreateInstructorBadPass() { + GeneralUserFactory g = new GeneralUserFactory(); + InstructorUser s = g.createInstructor("Hardcase", "2468"); + Assertions.assertFalse(s.checkPassword()); + } +} diff --git a/src/test/java/user_register_usecase/UserRegInteractorTest.java b/src/test/java/user_register_usecase/UserRegInteractorTest.java new file mode 100644 index 0000000..c926379 --- /dev/null +++ b/src/test/java/user_register_usecase/UserRegInteractorTest.java @@ -0,0 +1,95 @@ +package user_register_usecase; + +import entities.GeneralUserFactory; +import entities.StudentUser; +import entities.UserFactory; +import org.junit.jupiter.api.Test; +import screens.login_registration.InMemoryUser; +import screens.login_registration.UserRegResponseFormatter; +import use_cases.login_registration.user_register_usecase.*; + +import java.io.IOException; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; + +public class UserRegInteractorTest { + + @Test + void create() throws IOException { + // To test the use case: + // 1) Create a UserRegisterInteractor and prerequisite objects + // (arguments for the UserRegisterInteractor constructor parameters) + // 2) create the Input Data + // 3) Call the use case User Input Boundary method to run the use case + // 4) Check that the Output Data passed to the Presenter is correct + // 5) Check that the expected changes to the data layer are there. + + // 1) UserRegisterInteractor and prerequisite objects + // We're going to need a place to save and look up information. We could + // use FileUser, but because unit tests are supposed to be independent + // that would make us also reset the file when we are done. + // Instead, we're going to "mock" that info using a short-lived solution + // that just keeps the info in a dictionary, and it won't be persistent. + // (Separately, elsewhere, we will need to test the FileUser works + // properly.) + UserRegGateway userRepository = new InMemoryUser(); + + // This creates an anonymous implementing class for the Output Boundary. + UserRegPresenter presenter = new UserRegResponseFormatter() { + + @Override + public UserRegResponse prepareSuccessView(UserRegResponse user) { + // 4) Check that the Output Data and associated changes + // are correct + assertEquals("paul", user.getLogin()); + assertNotNull(user.getCreationTime()); // any creation time is fine. + assertTrue(userRepository.existsByName("paul")); + return null; + } + + @Override + public UserRegResponse prepareFailView(String error) { + fail("Use case failure is unexpected."); + return null; + } + }; + + UserFactory userFactory = new GeneralUserFactory(); + UserRegInputBoundary interactor = new UserRegInteractor( + userRepository, presenter, userFactory); + + // 2) Input data — we can make this up for the test. Normally it would + // be created by the Controller. + UserRegRequest inputData = new UserRegRequest( + "paul", "pwd1234567", "pwd1234567", "Student"); + + // 3) Run the use case + interactor.create(inputData); + } + + LocalDateTime now = LocalDateTime.now(); + StudentUser s = new StudentUser("Saje", "diffusers"); + UserRegGateway userRepository = new InMemoryUser(); + UserRegPresenter presenter = new UserRegResponseFormatter(); + UserFactory userFactory = new GeneralUserFactory(); + UserRegInputBoundary interactor2 = new UserRegInteractor(userRepository, presenter, userFactory); + UserRegRequest inputData = new UserRegRequest( + "Saje", "diffusers", "diffusers", "Student"); + +// interactor.create(inputData); + + + @Test + void testGetUserRegSaveRequest() throws IOException { + + StudentSaveRequest ussr = new StudentSaveRequest("Saje", "diffusers", s, now); + ((UserRegInteractor) interactor2).create(inputData); + UserRegSaveRequest ussr2 = ((UserRegInteractor) interactor2).getUserSaveRequest(now); + assertTrue(ussr.getName().equals(ussr2.getName())); + assertTrue(ussr.getPass().equals(ussr2.getPass())); + assertTrue(ussr instanceof StudentSaveRequest); + + } +} From 27f29bfe8e479bbf892239aa4e399bc35d37fbfc Mon Sep 17 00:00:00 2001 From: Natalie Duarte <96992022+CC-3636@users.noreply.github.com> Date: Thu, 1 Dec 2022 14:58:27 -0500 Subject: [PATCH 10/20] Delete UserFactory in Entities folder (duplicate there) --- src/main/java/Entities/UserFactory.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/main/java/Entities/UserFactory.java diff --git a/src/main/java/Entities/UserFactory.java b/src/main/java/Entities/UserFactory.java deleted file mode 100644 index 2ec53e4..0000000 --- a/src/main/java/Entities/UserFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -package entities; - - -// Entity Layer - -public interface UserFactory { - /** - * Creates Users with the specified name and password - */ - StudentUser createStudent(String name, String password); - - InstructorUser createInstructor(String name, String password); -} From 6c04a0b3fe615eb9f01c7ac388b56adca58d79a9 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 19:58:32 -0500 Subject: [PATCH 11/20] added some more tests & made some bug fixes based on testing --- .../screens/login_registration/FileUser.java | 9 --- .../login_registration/InMemoryUser.java | 3 +- .../LogoutResponseFormatter.java | 17 +++++ .../logout_usecase/LogoutInteractor.java | 2 +- .../logout_usecase/LogoutPresenter.java | 1 + .../InstructorSaveRequest.java | 3 + .../StudentSaveRequest.java | 3 + .../user_register_usecase/UserRegRequest.java | 2 +- .../UserRegSaveRequest.java | 7 +- src/test/java/FileUserTest.java | 63 +++++++++++++++-- .../login_usecase/LoginInteractorTest.java | 64 ++++++++++++++++++ .../logout_usecase/LogoutInteractorTest.java | 58 ++++++++++++++++ .../UserRegInteractorTest.java | 2 - .../UserRegRequestTest.java | 24 +++++++ .../UserRegSaveRequestTest.java | 37 ++++++++++ users.ser | Bin 937 -> 1176 bytes 16 files changed, 273 insertions(+), 22 deletions(-) create mode 100644 src/main/java/screens/login_registration/LogoutResponseFormatter.java create mode 100644 src/test/java/login_usecase/LoginInteractorTest.java create mode 100644 src/test/java/logout_usecase/LogoutInteractorTest.java create mode 100644 src/test/java/user_register_usecase/UserRegRequestTest.java create mode 100644 src/test/java/user_register_usecase/UserRegSaveRequestTest.java diff --git a/src/main/java/screens/login_registration/FileUser.java b/src/main/java/screens/login_registration/FileUser.java index 9808b90..5b7b9c9 100644 --- a/src/main/java/screens/login_registration/FileUser.java +++ b/src/main/java/screens/login_registration/FileUser.java @@ -88,13 +88,4 @@ public Map getAccounts() { return this.accounts; } -// /** -// * @param name The username of the user -// * @return the UserRegSaveRequest object associated with this username. -// * Preconditions: name is a key in accounts -// */ -// public UserRegSaveRequest getUserSaveReq(String name) throws KeyException, IOException { -//// accounts.get(name); -// return accounts.get(name); -// } } diff --git a/src/main/java/screens/login_registration/InMemoryUser.java b/src/main/java/screens/login_registration/InMemoryUser.java index 3dbdf06..77d11b2 100644 --- a/src/main/java/screens/login_registration/InMemoryUser.java +++ b/src/main/java/screens/login_registration/InMemoryUser.java @@ -1,13 +1,14 @@ package screens.login_registration; import use_cases.login_registration.login_usecase.LoginGateway; +import use_cases.login_registration.logout_usecase.LogoutGateway; import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; import use_cases.login_registration.user_register_usecase.UserRegGateway; import java.util.HashMap; import java.util.Map; -public class InMemoryUser implements UserRegGateway, LoginGateway { +public class InMemoryUser implements UserRegGateway, LoginGateway, LogoutGateway { final private Map users = new HashMap<>(); diff --git a/src/main/java/screens/login_registration/LogoutResponseFormatter.java b/src/main/java/screens/login_registration/LogoutResponseFormatter.java new file mode 100644 index 0000000..c625e26 --- /dev/null +++ b/src/main/java/screens/login_registration/LogoutResponseFormatter.java @@ -0,0 +1,17 @@ +package screens.login_registration; + +import use_cases.login_registration.logout_usecase.LogoutPresenter; +import use_cases.login_registration.logout_usecase.LogoutResponseModel; + +public class LogoutResponseFormatter implements LogoutPresenter { + + /** + * @param logout the logout response + * @return the successful logout view + */ + @Override + public LogoutResponseModel prepareSuccessView(LogoutResponseModel logout) { + return logout; + } + +} diff --git a/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java b/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java index edeecbf..4470846 100644 --- a/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java +++ b/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java @@ -38,7 +38,7 @@ public LogoutInteractor(LogoutGateway gateway, LogoutPresenter logoutPresenter, * log out into the User database. * @param request the request to logout * @return the logout response - * @throws IOException + * @throws IOException if logout fails */ @Override public LogoutResponseModel create(LogoutRequestModel request) throws IOException { diff --git a/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java b/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java index 8ed055e..dfbcd97 100644 --- a/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java +++ b/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java @@ -8,4 +8,5 @@ public interface LogoutPresenter { */ LogoutResponseModel prepareSuccessView(LogoutResponseModel logout); + } diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java index edf645c..e23528f 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java @@ -26,6 +26,9 @@ public class InstructorSaveRequest extends UserRegSaveRequest { */ public InstructorSaveRequest(String name, String password, InstructorUser instructor, LocalDateTime creationTime) { super(name, password, instructor, creationTime); + this.name = name; + this.password = password; + this.creationTime = creationTime; this.courses = instructor.getCourses(); } diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java index d8eb789..30d9163 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java @@ -41,6 +41,9 @@ public class StudentSaveRequest extends UserRegSaveRequest { */ public StudentSaveRequest(String name, String password, StudentUser student, LocalDateTime creationTime) { super(name, password, student, creationTime); + this.name = name; + this.password = password; + this.creationTime = creationTime; this.toDoList = student.getToDoList(); this.taskArchive = student.getTaskArchive(); this.courses = student.getCourses(); diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java index 967b30f..44d617c 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java @@ -45,7 +45,7 @@ public void setReenterPassword(String reenterPassword) { String getTypeOfUser() { return typeOfUser; } - String setTypeOfUser(String userType) { + public String setTypeOfUser(String userType) { if (userType.equals("Instructor") | userType.equals("Student")) { this.typeOfUser = userType; return "Success"; diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java index f70f223..ea0005d 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java @@ -1,6 +1,7 @@ package use_cases.login_registration.user_register_usecase; import entities.InstructorUser; +import entities.StudentUser; import entities.User; import java.io.Serializable; @@ -47,8 +48,12 @@ public LocalDateTime getCreationTime() { return creationTime; } + /** + * @return a User based on the information stored in this UserRegSaveRequest object + * Default is StudentUser + */ public User initializeUser() { - return null; + return new StudentUser(this.name, this.password); } } diff --git a/src/test/java/FileUserTest.java b/src/test/java/FileUserTest.java index 45eea34..f4709c1 100644 --- a/src/test/java/FileUserTest.java +++ b/src/test/java/FileUserTest.java @@ -1,16 +1,65 @@ +import entities.InstructorUser; +import entities.StudentUser; import org.junit.jupiter.api.Test; +import screens.login_registration.FileUser; +import use_cases.login_registration.user_register_usecase.InstructorSaveRequest; +import use_cases.login_registration.user_register_usecase.StudentSaveRequest; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.*; public class FileUserTest { + // Can it save a StudentUser and an InstructorUser? + // Can it read the file? Is the data preserved? + // Does it save updates to users? + + StudentUser student = new StudentUser("dhakaad", "badassb4real"); + InstructorUser instructor = new InstructorUser("zinda", "bollywood"); + StudentSaveRequest ssri = new StudentSaveRequest("dhakaad", "badassb4real", student, + LocalDateTime.now()); + InstructorSaveRequest bruh = new InstructorSaveRequest("zinda", "bollywood", instructor, + LocalDateTime.now()); + + public FileUserTest() throws IOException, ClassNotFoundException { + } + @Test - void saveStudentUser() { -// StudentUser student = new StudentUser("gma", "veryverysad"); -// StudentSaveRequest ssri = new StudentSaveRequest("gma", "veryverysad", student, -// LocalDateTime.now()); -// FileUser2 f_u = new FileUser2("./userstest.ser"); -// f_u.save(ssri); -// System.out.println(f_u.getAccounts()); + void saveUsers() throws IOException, ClassNotFoundException { + FileUser f_u = new FileUser("userstest.ser"); + f_u.save(ssri); + assert f_u.existsByName("dhakaad"); + f_u.save(bruh); + assert f_u.existsByName("zinda"); + } + + StudentSaveRequest ssri2 = new StudentSaveRequest("plant", "vanillawhey", student, + LocalDateTime.now()); + InstructorSaveRequest bruh2 = new InstructorSaveRequest("cacti", "waterbottle", + instructor, LocalDateTime.now()); + + @Test + void readUsers() throws IOException, ClassNotFoundException { + FileUser f_u2 = new FileUser("userstest.ser"); + f_u2.save(ssri2); + f_u2.save(bruh2); + Set s = f_u2.getAccounts().keySet(); + String[] names = {"zinda", "dhakaad", "plant", "cacti"}; + assert s.containsAll(List.of(names)); + } + + StudentSaveRequest ssri3 = new StudentSaveRequest("plant", "changedPass", student, + LocalDateTime.now()); + @Test + void updateUsers() throws IOException, ClassNotFoundException { + FileUser f_u3 = new FileUser("userstest.ser"); + f_u3.save(ssri3); + Map accounts = f_u3.getAccounts(); + StudentSaveRequest s = (StudentSaveRequest) accounts.get("plant"); + assert s.getPass().equals("changedPass"); + } diff --git a/src/test/java/login_usecase/LoginInteractorTest.java b/src/test/java/login_usecase/LoginInteractorTest.java new file mode 100644 index 0000000..aad281d --- /dev/null +++ b/src/test/java/login_usecase/LoginInteractorTest.java @@ -0,0 +1,64 @@ +package login_usecase; + +import entities.GeneralUserFactory; +import entities.InstructorUser; +import entities.User; +import entities.UserFactory; +import org.junit.jupiter.api.Test; +import screens.login_registration.InMemoryUser; +import screens.login_registration.LoginFailed; +import screens.login_registration.LoginResponseFormatter; +import screens.login_registration.UserRegResponseFormatter; +import use_cases.login_registration.login_usecase.*; +import use_cases.login_registration.user_register_usecase.*; + +import java.io.IOException; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; + +public class LoginInteractorTest { + + + @Test + void create() throws IOException, LoginFailed { + + InstructorUser u = new InstructorUser("paul", "pwd1234567"); + InstructorSaveRequest i = new InstructorSaveRequest("paul", "pwd1234567", + u, LocalDateTime.now()); + LoginGateway userRepository = new InMemoryUser(); + ((InMemoryUser) userRepository).save(i); + + // This creates an anonymous implementing class for the Output Boundary. + LoginPresenter presenter = new LoginResponseFormatter() { + + @Override + public LoginResponseModel prepareSuccessView(LoginResponseModel login) { + // 4) Check that the Output Data and associated changes + // are correct + assertEquals("paul", login.getName()); + assertNotNull(login.getLoginTime()); // any creation time is fine. + assertTrue(userRepository.existsByName("paul")); + return null; + } + + @Override + public LoginResponseModel prepareFailView(String error) { + fail("Use case failure is unexpected."); + return null; + } + }; + + LoginInteractor interactor = new LoginInteractor(userRepository, presenter); + + // 2) Input data — we can make this up for the test. Normally it would + // be created by the Controller. + LoginRequestModel inputData = new LoginRequestModel("paul", "pwd1234567"); + + // 3) Run the use case + interactor.create(inputData); + + } + +} diff --git a/src/test/java/logout_usecase/LogoutInteractorTest.java b/src/test/java/logout_usecase/LogoutInteractorTest.java new file mode 100644 index 0000000..be88ba4 --- /dev/null +++ b/src/test/java/logout_usecase/LogoutInteractorTest.java @@ -0,0 +1,58 @@ +package logout_usecase; + +import entities.GeneralUserFactory; +import entities.InstructorUser; +import entities.User; +import entities.UserFactory; +import org.junit.jupiter.api.Test; +import screens.login_registration.InMemoryUser; +import screens.login_registration.LogoutResponseFormatter; +import screens.login_registration.UserRegResponseFormatter; +import use_cases.login_registration.logout_usecase.*; +import use_cases.login_registration.user_register_usecase.*; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; + +public class LogoutInteractorTest { + + @Test + void create() throws IOException { + + LogoutGateway userRepository = new InMemoryUser(); + + // This creates an anonymous implementing class for the Output Boundary. + LogoutPresenter presenter = new LogoutResponseFormatter() { + + @Override + public LogoutResponseModel prepareSuccessView(LogoutResponseModel logout) { + // 4) Check that the Output Data and associated changes + // are correct + assertEquals("paul", logout.getName()); + assertNotNull(logout.getLogoutTime()); // any creation time is fine. + return null; + } + + public LogoutResponseModel prepareFailView(String error) { + fail("Use case failure is unexpected."); + return null; + } + + }; + + User u = new InstructorUser("paul", "123456789"); + LogoutInputBoundary interactor = new LogoutInteractor(userRepository, presenter, u); + + // 2) Input data — we can make this up for the test. Normally it would + // be created by the Controller. + LogoutRequestModel request = new LogoutRequestModel(); + + // 3) Run the use case + interactor.create(request); + + // was the user saved after logout? + assert ((InMemoryUser) userRepository).existsByName("paul"); + } +} diff --git a/src/test/java/user_register_usecase/UserRegInteractorTest.java b/src/test/java/user_register_usecase/UserRegInteractorTest.java index c926379..eaa43e6 100644 --- a/src/test/java/user_register_usecase/UserRegInteractorTest.java +++ b/src/test/java/user_register_usecase/UserRegInteractorTest.java @@ -78,8 +78,6 @@ public UserRegResponse prepareFailView(String error) { UserRegRequest inputData = new UserRegRequest( "Saje", "diffusers", "diffusers", "Student"); -// interactor.create(inputData); - @Test void testGetUserRegSaveRequest() throws IOException { diff --git a/src/test/java/user_register_usecase/UserRegRequestTest.java b/src/test/java/user_register_usecase/UserRegRequestTest.java new file mode 100644 index 0000000..eefd215 --- /dev/null +++ b/src/test/java/user_register_usecase/UserRegRequestTest.java @@ -0,0 +1,24 @@ +package user_register_usecase; + +import org.junit.jupiter.api.Test; +import use_cases.login_registration.user_register_usecase.UserRegRequest; + +public class UserRegRequestTest { + + @Test + void testSetTypeOfUserDoesntWork() { + // doesn't matter if password is valid or not, because UserRegRequest does not worry about that + UserRegRequest r = new UserRegRequest("Poha", "small", "small", + "Student"); + String s = r.setTypeOfUser("Stu"); + assert s.equals("User type can only be Instructor or Student"); + } + + @Test + void testSetTypeOfUserWorks() { + UserRegRequest r = new UserRegRequest("Poha", "small", "small", + "Student"); + String s = r.setTypeOfUser("Instructor"); + assert s.equals("Success"); + } +} diff --git a/src/test/java/user_register_usecase/UserRegSaveRequestTest.java b/src/test/java/user_register_usecase/UserRegSaveRequestTest.java new file mode 100644 index 0000000..3d8471b --- /dev/null +++ b/src/test/java/user_register_usecase/UserRegSaveRequestTest.java @@ -0,0 +1,37 @@ +package user_register_usecase; + +import entities.InstructorUser; +import entities.StudentUser; +import entities.User; +import org.junit.jupiter.api.Test; +import use_cases.login_registration.user_register_usecase.InstructorSaveRequest; +import use_cases.login_registration.user_register_usecase.StudentSaveRequest; +import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; + +import java.time.LocalDateTime; + +public class UserRegSaveRequestTest { + + @Test + void testinitializeStudentUser() { + StudentUser u = new StudentUser("poodles", "flooperflopple"); + StudentSaveRequest ussr = new StudentSaveRequest("poodles", "flooperflopple", u, + LocalDateTime.now()); + User u2 = ussr.initializeUser(); + assert u2 != null; + assert u2.getName().equals("poodles"); + assert u2.getPass().equals("flooperflopple"); + } + + @Test + void testinitializeInstructorUser() { + InstructorUser u = new InstructorUser("poodles", "flooperflopple"); + InstructorSaveRequest ussr = new InstructorSaveRequest("poodles", "flooperflopple", u, + LocalDateTime.now()); + User u2 = ussr.initializeUser(); + assert u2 != null; + assert u2.getName().equals("poodles"); + assert u2.getPass().equals("flooperflopple"); + } + +} diff --git a/users.ser b/users.ser index 9747cc969550703fb3c91c91d9f6e9442cf63bbb..321dfe42fdea2ff8b334b92aaef9a3105f74d362 100644 GIT binary patch delta 138 zcmZ3sX?iQ zrK!awt?SlZ=@av`VPatMVPH?rFD)ugEiPoJV_=#5ozYMc#Nq(+xyt!i85r1~@h}SU bo2g$ZF{l8^$xYT`mK6Z8z)IynETswn?cXR< delta 14 VcmbQixsrWC03*}Jz;I^93IHK21PTBE From 2bb89399105c5a8653302ff7f777916a8b716527 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 20:02:28 -0500 Subject: [PATCH 12/20] added UserFactory back in, let's see fi checks pass --- src/main/java/entities/UserFactory.java | 10 ++++++---- userstest.ser | Bin 0 -> 1296 bytes 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 userstest.ser diff --git a/src/main/java/entities/UserFactory.java b/src/main/java/entities/UserFactory.java index 2ec53e4..7b5b326 100644 --- a/src/main/java/entities/UserFactory.java +++ b/src/main/java/entities/UserFactory.java @@ -1,13 +1,15 @@ package entities; - -// Entity Layer - public interface UserFactory { /** - * Creates Users with the specified name and password + * + * @param name the name of this user + * @param password the password of this user + * @return a User object */ + StudentUser createStudent(String name, String password); InstructorUser createInstructor(String name, String password); + } diff --git a/userstest.ser b/userstest.ser new file mode 100644 index 0000000000000000000000000000000000000000..1d917a291fdc0438dbd47e35126c74c729f9943f GIT binary patch literal 1296 zcmbVM&uddb5T52o)3mRxZLlC(4_>q&30N;xK?}7e5J4I}O5MD-CTpH=Uw0?TYY&2; z2QNM8p$GBevG(9a@FqozM~esXDtOa>L1(vVoA`2&1~Tl<%+7o>-^|kDXvUHih zz>pggxuybUTqgHid=}IS6;vXqk!>hsTDPV0R^Sl~MhdPUp`JTb6G0GXf8KyKpF%-qiN z$V5pXWUJEmSKCs0^gee;^+D63$Gg)TJM3i=21=09VvR?k;kBJI(uNtfv5Xi&$areJ>^mu?>O?jPt_Iu*Z#(DyV4;ePei0~ddjgERW>TxX;_iiXgCxr2?QJ~=^ z_R=D#N{gIASenh#L3$cU6!(Q|Cq#F0^m1LM8kug)E4MCMeBTA-f;1D>xjQr(4Vsjq z8Aq$L*)sN=?V)1i)p=_hLvX5$c0*S$(un%jm6+>k^rY27XS3j7vmom0KGs*8i)mwu zkTx}>iAQT0x3UZN+=bb9e=yp2LKt!Dv>x2MMet+6O#P><_P>Eo_YHD7rj02KaF@PC n!djA6b^)JtQlA>%3~=j2z}vL%swxqE9t&oGpEcr~5i`+W8U=I& literal 0 HcmV?d00001 From 951a596c6c8c5875baf1ecc0f672af6e5a5265a6 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 20:55:27 -0500 Subject: [PATCH 13/20] login GUI done finally praise God --- src/main/java/Main.java | 15 +++++++-- .../login_registration/LoginScreen.java | 32 ++++++++++++------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a18e7db..f324f3d 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -11,6 +11,10 @@ import use_cases.collaborative_task_scheduling.scheduling_ct_use_case.*; import use_cases.calendar_scheduler.schedule_conflict_use_case.ScheduleConflictPresenter; import use_cases.calendar_scheduler.scheduler_use_case.SchedulerPresenter; +import use_cases.login_registration.login_usecase.LoginGateway; +import use_cases.login_registration.login_usecase.LoginInputBoundary; +import use_cases.login_registration.login_usecase.LoginInteractor; +import use_cases.login_registration.login_usecase.LoginPresenter; import use_cases.login_registration.user_register_usecase.*; import use_cases.task_management.event_creation_use_case.*; @@ -41,6 +45,13 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio UserRegInputBoundary userInteractor = new UserRegInteractor(regUser, userPresenter, fac); UserRegController userRegisterController = new UserRegController(userInteractor); + // Adding in login use case + LoginGateway loginUser = new FileUser("users.ser"); + LoginPresenter loginPresenter = new LoginResponseFormatter(); + LoginInputBoundary loginInteractor = new LoginInteractor(loginUser, loginPresenter); + LoginController loginController = new LoginController(loginInteractor); + // + User user = ((UserRegInteractor) userInteractor).getUser(); SchedulerPresenter schedulerPresenter = new SchedulerResponseFormatter(); @@ -93,8 +104,8 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio RegisterScreen registerScreen = new RegisterScreen(userRegisterController, cardLayout, screens); screens.add("register", registerScreen); -// LoginScreen loginScreen = new LoginScreen(loginController); -// screens.add("login", loginScreen); + LoginScreen loginScreen = new LoginScreen(loginController, cardLayout, screens); + screens.add("login", loginScreen); WelcomeScreen welcomeScreen = new WelcomeScreen(cardLayout, screens); screens.add("welcome", welcomeScreen); diff --git a/src/main/java/screens/login_registration/LoginScreen.java b/src/main/java/screens/login_registration/LoginScreen.java index 555232c..d2645f4 100644 --- a/src/main/java/screens/login_registration/LoginScreen.java +++ b/src/main/java/screens/login_registration/LoginScreen.java @@ -9,7 +9,7 @@ import static javax.swing.JOptionPane.showMessageDialog; -public class LoginScreen extends JFrame implements ActionListener { +public class LoginScreen extends JPanel implements ActionListener { /** * The username chosen by the user */ @@ -21,8 +21,14 @@ public class LoginScreen extends JFrame implements ActionListener { LoginController loginController; - public LoginScreen(LoginController controller) { + CardLayout cardLayout; + + JPanel screens; + + public LoginScreen(LoginController controller, CardLayout cardLayout, JPanel screens) { this.loginController = controller; + this.cardLayout = cardLayout; + this.screens = screens; JLabel title = new JLabel("Login Screen"); title.setAlignmentX(Component.CENTER_ALIGNMENT); @@ -42,16 +48,17 @@ public LoginScreen(LoginController controller) { logIn.addActionListener(this); cancel.addActionListener(this); - JPanel main = new JPanel(); - main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); - - main.add(title); - main.add(usernameInfo); - main.add(passwordInfo); - main.add(buttons); - this.setContentPane(main); - - this.pack(); +// JPanel main = new JPanel(); +// main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + +// this.add(title); + this.add(usernameInfo); + this.add(passwordInfo); + this.add(buttons); +// this.setContentPane(main); +// +// this.pack(); } /** @@ -64,6 +71,7 @@ public void actionPerformed(ActionEvent evt) { loginController.create(username.getText(), String.valueOf(password.getPassword())); showMessageDialog(this, "% logged in.".format(username.getText())); + cardLayout.show(screens, "main"); } catch (Exception e) { showMessageDialog(this, e.getMessage()); } catch (LoginFailed e) { From e2c2b7432f184d8d4289bc1f665cf61226e0cc63 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 21:02:44 -0500 Subject: [PATCH 14/20] logout GUI done yas --- src/main/java/screens/MainScreen.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/screens/MainScreen.java b/src/main/java/screens/MainScreen.java index 3ef9199..7f56e01 100644 --- a/src/main/java/screens/MainScreen.java +++ b/src/main/java/screens/MainScreen.java @@ -16,6 +16,8 @@ public class MainScreen extends JPanel implements ActionListener { JButton courses; JButton scheduleCT; + JButton logout; + /** * Objects for connecting to the other screens */ @@ -40,12 +42,14 @@ public MainScreen(JPanel screens, CardLayout cardLayout) { progressTracker = new JButton("Progress Tracker"); courses = new JButton("Courses"); scheduleCT = new JButton("Schedule Collaborative Task"); + logout = new JButton("Logout"); toDoList.addActionListener(this); calendar.addActionListener(this); progressTracker.addActionListener(this); courses.addActionListener(this); scheduleCT.addActionListener(this); + logout.addActionListener(this); // Create panel for buttons JPanel buttons = new JPanel(); @@ -54,6 +58,7 @@ public MainScreen(JPanel screens, CardLayout cardLayout) { buttons.add(progressTracker); buttons.add(courses); buttons.add(scheduleCT); + buttons.add(logout); // Add all components to the panel this.add(title); @@ -80,6 +85,9 @@ public void actionPerformed(ActionEvent evt) { if (evt.getSource() == scheduleCT) { cardLayout.show(screens, "scheduleCT"); } + if (evt.getSource() == logout) { + cardLayout.show(screens, "welcome"); + } } From 7b45b10b8d0840731126e8a69fca65bcf029de0d Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 21:23:03 -0500 Subject: [PATCH 15/20] made Cancel button functional in login and register screens --- .../login_registration/LoginScreen.java | 23 ++++++++++-------- .../login_registration/RegisterScreen.java | 23 +++++++++++------- users.ser | Bin 1176 -> 1259 bytes 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/screens/login_registration/LoginScreen.java b/src/main/java/screens/login_registration/LoginScreen.java index d2645f4..d528449 100644 --- a/src/main/java/screens/login_registration/LoginScreen.java +++ b/src/main/java/screens/login_registration/LoginScreen.java @@ -66,16 +66,19 @@ public LoginScreen(LoginController controller, CardLayout cardLayout, JPanel scr */ public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); - - try { - loginController.create(username.getText(), - String.valueOf(password.getPassword())); - showMessageDialog(this, "% logged in.".format(username.getText())); - cardLayout.show(screens, "main"); - } catch (Exception e) { - showMessageDialog(this, e.getMessage()); - } catch (LoginFailed e) { - throw new RuntimeException(e); + if (evt.getActionCommand().equals("Cancel")) { + cardLayout.show(screens, "welcome"); + } else { + try { + loginController.create(username.getText(), + String.valueOf(password.getPassword())); + showMessageDialog(this, "% logged in.".format(username.getText())); + cardLayout.show(screens, "main"); + } catch (Exception e) { + showMessageDialog(this, e.getMessage()); + } catch (LoginFailed e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/screens/login_registration/RegisterScreen.java b/src/main/java/screens/login_registration/RegisterScreen.java index 3679d6d..a6d1e39 100644 --- a/src/main/java/screens/login_registration/RegisterScreen.java +++ b/src/main/java/screens/login_registration/RegisterScreen.java @@ -102,15 +102,20 @@ public RegisterScreen(UserRegController controller, CardLayout cardLayout, JPane public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); - try { - userRegController.create(username.getText(), - String.valueOf(password.getPassword()), - String.valueOf(repeatPassword.getPassword()), - String.valueOf(typeOfUser.getText())); - showMessageDialog(this, "%s created.".format(username.getText())); - cardLayout.show(screens, "main"); - } catch (Exception e) { - showMessageDialog(this, e.getMessage()); + if (evt.getActionCommand().equals("Cancel")) { + cardLayout.show(screens, "welcome"); + } else { + try { + userRegController.create(username.getText(), + String.valueOf(password.getPassword()), + String.valueOf(repeatPassword.getPassword()), + String.valueOf(typeOfUser.getText())); + showMessageDialog(this, "%s created.".format(username.getText())); + cardLayout.show(screens, "main"); + + } catch (Exception e) { + showMessageDialog(this, e.getMessage()); + } } } } \ No newline at end of file diff --git a/users.ser b/users.ser index 321dfe42fdea2ff8b334b92aaef9a3105f74d362..62e6899ab6ec8e656556ed981d1c46904489930e 100644 GIT binary patch delta 99 zcmbQi`I>V=03*xBz>Q4oOnE8AMGPJjQ3kUo)#SicH?eB0JfDC6~E~!DC{)@njq35?&#GGxaMa1{H-2 SbqsPq1&Tb1U?zxAssI4i920o} From d040e6d99b1cb6c5347884f744bb51e526d3f76c Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Thu, 1 Dec 2022 22:18:32 -0500 Subject: [PATCH 16/20] made the dashboard different so that logging in or registering as an Instructor shows a different dashboard than for a Student --- src/main/java/Main.java | 4 + src/main/java/screens/InstructorMain.java | 88 ++++++++++++++++++ .../login_registration/LoginScreen.java | 9 +- .../login_registration/RegisterScreen.java | 6 +- .../login_usecase/LoginInteractor.java | 10 +- .../login_usecase/LoginResponseModel.java | 13 ++- users.ser | Bin 1259 -> 1431 bytes 7 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 src/main/java/screens/InstructorMain.java diff --git a/src/main/java/Main.java b/src/main/java/Main.java index f324f3d..ca0b0b0 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -54,6 +54,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio User user = ((UserRegInteractor) userInteractor).getUser(); + SchedulerPresenter schedulerPresenter = new SchedulerResponseFormatter(); ScheduleConflictPresenter scheduleConflictPresenter = new ScheduleConflictResponseFormatter(); @@ -107,6 +108,9 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio LoginScreen loginScreen = new LoginScreen(loginController, cardLayout, screens); screens.add("login", loginScreen); + InstructorMain instructorMainScreen = new InstructorMain(screens, cardLayout); + screens.add("InstructorMain", instructorMainScreen); + WelcomeScreen welcomeScreen = new WelcomeScreen(cardLayout, screens); screens.add("welcome", welcomeScreen); diff --git a/src/main/java/screens/InstructorMain.java b/src/main/java/screens/InstructorMain.java new file mode 100644 index 0000000..b7b2af1 --- /dev/null +++ b/src/main/java/screens/InstructorMain.java @@ -0,0 +1,88 @@ +package screens; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class InstructorMain extends JPanel implements ActionListener { + + + /** + * The selectable buttons on the main screen + */ + JButton toDoList; + JButton calendar; + JButton courses; + JButton scheduleCT; + + JButton logout; + + /** + * Objects for connecting to the other screens + */ + CardLayout cardLayout; + JPanel screens; + + /** + * The window of the main screen with buttons connecting to each use case + */ + public InstructorMain(JPanel screens, CardLayout cardLayout) { + + this.cardLayout = cardLayout; + this.screens = screens; + + // Create label for title of screen + JLabel title = new JLabel("32 Things To Do"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + + // Create buttons + toDoList = new JButton("New Task"); + calendar = new JButton("Calendar"); + courses = new JButton("Courses"); +// scheduleCT = new JButton("Schedule Collaborative Task"); + logout = new JButton("Logout"); + + toDoList.addActionListener(this); + calendar.addActionListener(this); + courses.addActionListener(this); +// scheduleCT.addActionListener(this); + logout.addActionListener(this); + + // Create panel for buttons + JPanel buttons = new JPanel(); + buttons.add(toDoList); + buttons.add(calendar); + buttons.add(courses); +// buttons.add(scheduleCT); + buttons.add(logout); + + // Add all components to the panel + this.add(title); + this.add(buttons); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + } + + /** + * Trigger the corresponding use case upon button click + */ + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == toDoList) { + cardLayout.show(screens, "toDoList"); + } + if (evt.getSource() == calendar) { + cardLayout.show(screens, "calendar"); + } + + if (evt.getSource() == courses) { + cardLayout.show(screens, "course"); + } +// if (evt.getSource() == scheduleCT) { +// cardLayout.show(screens, "scheduleCT"); +// } + if (evt.getSource() == logout) { + cardLayout.show(screens, "welcome"); + } + + } +} diff --git a/src/main/java/screens/login_registration/LoginScreen.java b/src/main/java/screens/login_registration/LoginScreen.java index d528449..b5d49f8 100644 --- a/src/main/java/screens/login_registration/LoginScreen.java +++ b/src/main/java/screens/login_registration/LoginScreen.java @@ -1,6 +1,7 @@ package screens.login_registration; import screens.LabelTextPanel; +import use_cases.login_registration.login_usecase.LoginResponseModel; import javax.swing.*; import java.awt.*; @@ -70,10 +71,14 @@ public void actionPerformed(ActionEvent evt) { cardLayout.show(screens, "welcome"); } else { try { - loginController.create(username.getText(), + LoginResponseModel l = loginController.create(username.getText(), String.valueOf(password.getPassword())); showMessageDialog(this, "% logged in.".format(username.getText())); - cardLayout.show(screens, "main"); + if (l.getTypeOfUser().equals("Instructor")) { + cardLayout.show(screens, "InstructorMain"); + } else { + cardLayout.show(screens, "main"); + } } catch (Exception e) { showMessageDialog(this, e.getMessage()); } catch (LoginFailed e) { diff --git a/src/main/java/screens/login_registration/RegisterScreen.java b/src/main/java/screens/login_registration/RegisterScreen.java index a6d1e39..69f9906 100644 --- a/src/main/java/screens/login_registration/RegisterScreen.java +++ b/src/main/java/screens/login_registration/RegisterScreen.java @@ -111,7 +111,11 @@ public void actionPerformed(ActionEvent evt) { String.valueOf(repeatPassword.getPassword()), String.valueOf(typeOfUser.getText())); showMessageDialog(this, "%s created.".format(username.getText())); - cardLayout.show(screens, "main"); + if (String.valueOf(typeOfUser.getText()).equals("Student")) { + cardLayout.show(screens, "main"); + } else if (String.valueOf(typeOfUser.getText()).equals("Instructor")) { + cardLayout.show(screens, "InstructorMain"); + } } catch (Exception e) { showMessageDialog(this, e.getMessage()); diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java b/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java index 18e54d4..2085d6f 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java @@ -1,5 +1,6 @@ package use_cases.login_registration.login_usecase; +import entities.InstructorUser; import entities.User; import screens.login_registration.LoginFailed; import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; @@ -42,9 +43,16 @@ public LoginResponseModel create(LoginRequestModel requestModel) throws LoginFai } LocalDateTime now = LocalDateTime.now(); - LoginResponseModel loginRes = new LoginResponseModel(requestModel.getName(), now.toString()); this.user = createUser(requestModel); + + LoginResponseModel loginRes; + + if (this.user instanceof InstructorUser) { + loginRes = new LoginResponseModel(requestModel.getName(), now.toString(), "Instructor"); + } else { + loginRes = new LoginResponseModel(requestModel.getName(), now.toString(), "Student"); + } return loginPresenter.prepareSuccessView(loginRes); } diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java b/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java index 3db6b5e..c592d69 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java @@ -9,19 +9,30 @@ public class LoginResponseModel { String loginTime; + String typeOfUser; + /** * @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) { + public LoginResponseModel(String username, String timeOfLogin, String typeOfUser) { this.name = username; this.loginTime = timeOfLogin; + this.typeOfUser = typeOfUser; } public String getName() { return name; } public void setName(String username) { this.name = username; } + public String getTypeOfUser() { return typeOfUser; } + + public void setTypeOfUser(String s) { + if (s.equals("Instructor") | s.equals("Student")) { + this.typeOfUser = s; + } + } + public String getLoginTime() { return loginTime; } diff --git a/users.ser b/users.ser index 62e6899ab6ec8e656556ed981d1c46904489930e..2610fb5b407fcbd56f893df1a11515845391172d 100644 GIT binary patch delta 631 zcmaFOIh}h#03TZk16x{VRaH)EaS?;Z#CYS$Hq2TRce+m2Wt8FPC`c?WF3&GYDP*W) zV5^uIV>bB~qm3Y&4+E;qWOXKWP98>4Lte)8T{e@$nLPMGI=Dat6NuoR7??3Rjaho) zKND84S(DuvRT$YO=P+6rgZS*lAd<73kClOe{Ta8Mkfbro?W;8vAW^;&22MjGV-r&| za|=tbI-bd@ELzDt3_wuM0wOC4AmVsMFqM=rFy*Cyg_*%5%zmIx1Y|YuiWW@fWf2cY zwg==M84w`_B4kS#STj;{a`M5t`BBW^mJ_sA7xy@G1MCNR?0%?6Hk({OuoNVg=3w`Q znm$Xzi3YF>G%;Pkz)%DaK#+H|L4+oV&?#Zy@JlR7%*jl3!D_M)znS`#5(BWwde}@x OG1vfPrXGketN;Loi;1@Y delta 470 zcmbQv{hD(^03*v}Q>KiGyIm*mU^1D^$|yehGm{b{`(!a@i^&d5W|I>cZ3NkU7&rKNE3uVYl_1qBJ&s|2K?wtgUt&pOPG+hLSW*;jDa0#6{ATJ`N({hWQ9<{LEJ~ Date: Thu, 1 Dec 2022 23:04:22 -0500 Subject: [PATCH 17/20] made some changes to Main to cover initialization of User (based on whether the person logs in or registers) --- src/main/java/Main.java | 10 +++++++++- .../UserRegInteractor.java | 13 +++++++++++-- users.ser | Bin 1431 -> 1695 bytes userstest.ser | Bin 1296 -> 1304 bytes 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index ca0b0b0..c81a690 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -52,7 +52,15 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio LoginController loginController = new LoginController(loginInteractor); // - User user = ((UserRegInteractor) userInteractor).getUser(); + // initialize User based on whether they log in or register + // if you don't register, then you are logging in: + User user; + if ((((UserRegInteractor) userInteractor).getUser() instanceof StudentUser) | + (((UserRegInteractor) userInteractor).getUser() instanceof InstructorUser)) { + user = ((UserRegInteractor) userInteractor).getUser(); + } else { + user = ((LoginInteractor) loginInteractor).getUser(); + } SchedulerPresenter schedulerPresenter = new SchedulerResponseFormatter(); diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java index 68c1fbf..88e2eb5 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java @@ -47,10 +47,15 @@ public UserRegResponse create(UserRegRequest request) throws IOException { return userPresenter.prepareFailView("Enter either 'Instructor' or 'Student'."); } + // can make userFactory have a createUser() method that takes in the Name, Pass, and typeOfUser + // and creates that type of user (with an if statement) + if (request.getTypeOfUser().equals("Instructor")) { this.user = userFactory.createInstructor(request.getName(), request.getPassword()); - } else { + } else if (request.getTypeOfUser().equals("Student")){ this.user = userFactory.createStudent(request.getName(), request.getPassword()); + } else { + this.user = null; } if (!user.checkPassword()) { @@ -100,6 +105,10 @@ public UserRegSaveRequest getUserSaveRequest(LocalDateTime now) { } public User getUser() { - return this.user; + if ((this.user instanceof StudentUser) | (this.user instanceof InstructorUser)) { + return this.user; + } else { + return null; + } } } diff --git a/users.ser b/users.ser index 2610fb5b407fcbd56f893df1a11515845391172d..e7786f482fb9905c9a99632596c1a524a425e458 100644 GIT binary patch delta 170 zcmbQvJ)d_%03*l7zYkGqZBYip%$%R(PRf2 Y%%#*mXYvge85wkUYl3uZfe7si0I4uR00000 delta 361 zcmbQiHGylxHAY@xK`Twm<5MaM8R{6ACO>2JW@7>|xi_0L=`tFDWVz?-fMxkg7UbD{pqvFnf)xo(p3N**k1ooGRjn|FD26~m2?J|EPGVjOScV@= za+dS4GBB_|<6#uGG&0`)zoY`DsDyz#IU_MIT_!ap0O(8%(?AZE0XfhP-GQ=L)yiRr iLIfsnV9{h3Hs)bDmVIOL0~Q$>bmP=PHfewe%?bc0=1hbD From f6a7ca6ab5c395a7139064a7597af64093839d42 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Fri, 2 Dec 2022 01:08:40 -0500 Subject: [PATCH 18/20] Made changes based on Tiare's feedback --- src/main/java/Main.java | 8 ++++---- src/main/java/data/users.ser | Bin 0 -> 781 bytes src/main/java/screens/InstructorMain.java | 10 +++++----- ...MainScreen.java => StudentMainScreen.java} | 4 ++-- .../screens/login_registration/FileUser.java | 8 +++++++- .../UserRegInteractor.java | 8 +++++--- src/main/java/users | 0 src/test/java/FileUserTest.java | 6 +++--- .../test/java/data/userstest.ser | Bin 1304 -> 1304 bytes users.ser | Bin 1695 -> 0 bytes 10 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 src/main/java/data/users.ser rename src/main/java/screens/{MainScreen.java => StudentMainScreen.java} (94%) delete mode 100644 src/main/java/users rename userstest.ser => src/test/java/data/userstest.ser (80%) delete mode 100644 users.ser diff --git a/src/main/java/Main.java b/src/main/java/Main.java index c81a690..a222b32 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -39,14 +39,14 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio HashMap allCourses = new HashMap<>(); // Create the components for injection into the use cases - UserRegGateway regUser = new FileUser("users.ser"); + UserRegGateway regUser = new FileUser("src/main/java/data/users.ser"); UserFactory fac = new GeneralUserFactory(); UserRegPresenter userPresenter = new UserRegResponseFormatter(); UserRegInputBoundary userInteractor = new UserRegInteractor(regUser, userPresenter, fac); UserRegController userRegisterController = new UserRegController(userInteractor); // Adding in login use case - LoginGateway loginUser = new FileUser("users.ser"); + LoginGateway loginUser = new FileUser("src/main/java/data/users.ser"); LoginPresenter loginPresenter = new LoginResponseFormatter(); LoginInputBoundary loginInteractor = new LoginInteractor(loginUser, loginPresenter); LoginController loginController = new LoginController(loginInteractor); @@ -107,8 +107,8 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio CourseCreationScreen courseCreationScreen = new CourseCreationScreen(courseCreationController, screens, cardLayout); screens.add("course", courseCreationScreen); - MainScreen mainScreen = new MainScreen(screens, cardLayout); - screens.add("main", mainScreen); + StudentMainScreen studentMainScreen = new StudentMainScreen(screens, cardLayout); + screens.add("main", studentMainScreen); RegisterScreen registerScreen = new RegisterScreen(userRegisterController, cardLayout, screens); screens.add("register", registerScreen); diff --git a/src/main/java/data/users.ser b/src/main/java/data/users.ser new file mode 100644 index 0000000000000000000000000000000000000000..2eed739a767f4459179d192b7f18353bdaa993f3 GIT binary patch literal 781 zcmbVKJ8#rL5T5wXaxU>fLIe^*G;}mR@dyv42$8~Zkqku+N)!fr@hvf4XLo#OD3Fk7 zXy_ z*D-g!uOG(8?tE#0(}k&2Vcf-tlwN@r4YV)=mBwYhcm?e8N0WTc@SY&>ZXjVQ1=C(F zj981%2ot0#k=dFSi8Q2N>&(dlnh=sfa~JeH@Bau~7&^uUgN3&c4}v?!Z(C zUZe`mgak)J+jPe^-C5EaABIf55P~0RQ5Co;9|(fuJ1}CW6RHT)Wh7x!3~k54NG;-P z8rdQ^yoZuCV1z5PyQ s = f_u2.getAccounts().keySet(); @@ -54,7 +54,7 @@ void readUsers() throws IOException, ClassNotFoundException { LocalDateTime.now()); @Test void updateUsers() throws IOException, ClassNotFoundException { - FileUser f_u3 = new FileUser("userstest.ser"); + FileUser f_u3 = new FileUser("src/test/java/data/userstest.ser"); f_u3.save(ssri3); Map accounts = f_u3.getAccounts(); StudentSaveRequest s = (StudentSaveRequest) accounts.get("plant"); diff --git a/userstest.ser b/src/test/java/data/userstest.ser similarity index 80% rename from userstest.ser rename to src/test/java/data/userstest.ser index 84b28063554955ef2dbab0691b6edbde8885bcf4..0050e15bf50d809541f4e1b455aadcc8483bae5f 100644 GIT binary patch delta 60 zcmbQiHG^xzRYndbMm9c%;+PAY?=rR_c$2f4w}7O0t@Y16nXJyT5zH~aQ*1N&0gD9y D1ho-N delta 60 zcmbQiHG^xzRYnd*ab^wv>}xff?=rR_c$2f4w}7Sic4>P|R%h7==5Q&s&zbyy#R32m Ct`P(P diff --git a/users.ser b/users.ser deleted file mode 100644 index e7786f482fb9905c9a99632596c1a524a425e458..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1695 zcmcgs%}*0i5TAb07MAZ60tyF1AVjhiK}3N731XX64^)o^pW8?KWZhlfzS5N#gNYuz zaPz>yn@8l}k((h#jb0>}_z_Pg#*6+9zIl|7T2c%Ln{@Ja-pp@)Gr!qg`voDFL*s3- zNc6m5rk)^f?h0{2;V&;YTW)>`fPWgQO`BwgH@S<2mCKfIqDek+wnp zBLb@C*wT_oC2At?(piJJ)YVNp%dA;Wv&W)C#8 z^=f)^?fctJKLq}wigiLoPO4@Z2S-k|R%wOZ=xNHI+<3Tg;#A^=2H-h`x)4D4hvtj* z*ZQ&>qaLF81w{ML4h)_fIzN0t<~Q$ay*D)P!B)rWYw|Pzz9a-)wnRM#g)IcpDwt}8 zg{DS8_$m>^WGM1+hLRTf47J38p*)K|{@wU|b;S?W`wC+*DR_yT=#w+5%}|$dnz_u0 zJPD{junKZ}rFtP|-Le&P387@h)GC>3*@De6Lv4s#tWm0UO7=+H`AKf%*dpBx5%!dg z8&-VQIB2A=yQf2=WRSa)0hkCZf83jCcB=9(5j-i?G{s0OhxOo5o From 683217b595896744930d006d0d8388a6f26de051 Mon Sep 17 00:00:00 2001 From: Natalie Duarte <96992022+CC-3636@users.noreply.github.com> Date: Fri, 2 Dec 2022 01:09:24 -0500 Subject: [PATCH 19/20] Deleted courses.csv --- src/main/java/data/courses.csv | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/java/data/courses.csv diff --git a/src/main/java/data/courses.csv b/src/main/java/data/courses.csv deleted file mode 100644 index 122444c..0000000 --- a/src/main/java/data/courses.csv +++ /dev/null @@ -1 +0,0 @@ -course_name,course_instructor,tasks? From ba898cf1beaa7c34c0ecf67c3f02899e97dd7b98 Mon Sep 17 00:00:00 2001 From: CC-3636 Date: Fri, 2 Dec 2022 15:14:39 -0500 Subject: [PATCH 20/20] Made FileUser's getAccounts() method static. Minor change to StudentUser based on Julie's feedback. --- src/main/java/data/users.ser | Bin 781 -> 1015 bytes src/main/java/entities/StudentUser.java | 2 +- .../screens/login_registration/FileUser.java | 12 ++++++++---- src/test/java/data/userstest.ser | Bin 1304 -> 1304 bytes 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/data/users.ser b/src/main/java/data/users.ser index 2eed739a767f4459179d192b7f18353bdaa993f3..8f6702e427ac07231145c6fb60234f6adaa3f098 100644 GIT binary patch delta 157 zcmeBW`_4WgfRSlq;BF?a5(eh<+{EG{29JsH#`>Ol#U(|h$tC$k!HH$5L8*nMsl_F& z>(*WA6Z5oTVqo!MU{B63Eh+5)}XhTq=41 delta 14 Vcmey)-pe*2fRS-y;BF?y3IHZ=1gro6 diff --git a/src/main/java/entities/StudentUser.java b/src/main/java/entities/StudentUser.java index 1f65111..0ef70b5 100644 --- a/src/main/java/entities/StudentUser.java +++ b/src/main/java/entities/StudentUser.java @@ -87,7 +87,7 @@ public ArrayList getCourses() { } public void addCourse(String course) { - this.toDoList.add(course); + this.courses.add(course); } public void setCourses(ArrayList c) { this.courses = c; } diff --git a/src/main/java/screens/login_registration/FileUser.java b/src/main/java/screens/login_registration/FileUser.java index 0053aca..caab839 100644 --- a/src/main/java/screens/login_registration/FileUser.java +++ b/src/main/java/screens/login_registration/FileUser.java @@ -12,7 +12,8 @@ public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway { - private final HashMap accounts; +// private final HashMap accounts; + private static HashMap accounts; private final String filePath; @@ -29,9 +30,11 @@ public FileUser(String path) throws IOException, ClassNotFoundException { // and reads the existing file if it does exist if (Files.exists(Path.of(path))) { - this.accounts = readFile(); +// this.accounts = readFile(); + accounts = readFile(); } else { - this.accounts = new HashMap(); +// this.accounts = new HashMap(); + accounts = new HashMap(); save(); } @@ -91,7 +94,8 @@ public String passOf(String name) { } public Map getAccounts() { - return this.accounts; +// return this.accounts; + return accounts; } } diff --git a/src/test/java/data/userstest.ser b/src/test/java/data/userstest.ser index 0050e15bf50d809541f4e1b455aadcc8483bae5f..4adea51d75d1eb0833fed45216c949ed6987c094 100644 GIT binary patch delta 56 zcmbQiHG^xzHAZ$mX*MzT?Nc`2Wo(CYCTBBm1xbj8)Et?t&aw%_7Vw;ZW%2_S3jozP B5Z3?z delta 56 zcmbQiHG^xzHAZ$uHa>>pm