Skip to content

Commit 9c9f76a

Browse files
committed
Added more documenation for getters, setters and testing.
1 parent db6be58 commit 9c9f76a

File tree

11 files changed

+254
-19
lines changed

11 files changed

+254
-19
lines changed

src/main/java/entities/CommonUser.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,61 @@ public CommonUser(String username, String password, boolean isAdmin){
3333
this.flashcardSetIds = new ArrayList<>();
3434
}
3535

36-
//GETTERS AND SETTERS
36+
/**
37+
* Gets the username of the user
38+
* @return the username of the user
39+
*/
3740
@Override
3841
public String getUsername() {
3942
return username;
4043
}
4144

45+
/**
46+
* Sets the username of the user to be as given.
47+
* @param username the username of the use
48+
*/
4249
public void setUsername(String username) {
4350
this.username = username;
4451
}
4552

53+
/**
54+
* Gets the password of the user
55+
* @return the password of the user
56+
*/
4657
@Override
4758
public String getPassword() {
4859
return password;
4960
}
5061

62+
/**
63+
* Sets the password of the user to be as given.
64+
* @param password the username of the use
65+
*/
5166
public void setPassword(String password) {
5267
this.password = password;
5368
}
5469

70+
/**
71+
* Gets the admin access level of the user
72+
* @return whether the user is an admin
73+
*/
5574
@Override
5675
public boolean getIsAdmin() {
5776
return isAdmin;
5877
}
5978

79+
/**
80+
* Sets the level of admin access the user has
81+
* @param isAdmin whether the user should obtain admin level access
82+
*/
6083
public void setIsAdmin(boolean isAdmin){
6184
this.isAdmin = isAdmin;
6285
}
6386

87+
/**
88+
* Gets the list of flashcard set ids belonging to the user
89+
* @return list of flashcard set ids
90+
*/
6491
@Override
6592
public ArrayList<Integer> getFlashcardSetIds() {
6693
return flashcardSetIds;
@@ -77,7 +104,7 @@ public boolean passwordIsValid() {
77104

78105
/**
79106
* Checks whether the admin key entered is similar to the actual admin key in the business rules
80-
* @param adminKey the username of the use
107+
* @param adminKey the username of the user
81108
* @return whether the admin is the same as the one stored in the enterprise rules
82109
*/
83110
@Override

src/main/java/entities/User.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@
1010
*/
1111
public interface User {
1212
String username = null;
13-
1413
String password = null;
1514
boolean isAdmin = false;
16-
String ADMIN_KEY = "BuiltDifferent";
17-
18-
//Map<Integer, String[]> flashcardSets = null;
19-
ArrayList<Integer> flashcardSetIds = null;
2015

16+
/**
17+
* Gets the username belonging to the user
18+
*/
2119
String getUsername();
2220

21+
/**
22+
* Gets the password belonging to the user
23+
*/
2324
String getPassword();
2425

26+
/**
27+
* Gets whether the user is an admin user
28+
*/
2529
boolean getIsAdmin();
2630

31+
/**
32+
* Gets the list of flashcard set ids belonging to the user
33+
*/
2734
ArrayList<Integer> getFlashcardSetIds();
2835

2936
/**

src/main/java/login_and_signup_use_case/UserLoginRequestModel.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ public UserLoginRequestModel(String username, String password) {
2121
}
2222

2323
/**
24-
* GETTERS AND SETTERS
24+
* Gets the inputted username of the user
25+
* @return the username that the user inputted
2526
*/
2627
String getUsername() {
2728
return username;
2829
}
2930

31+
/**
32+
* Sets the inputted password of the user to be as given.
33+
* @return the password that the user inputted
34+
*/
3035
String getPassword() {
3136
return password;
3237
}

src/main/java/login_and_signup_use_case/UserLoginResponseModel.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ public UserLoginResponseModel(String loggedInUsername, boolean isAdmin, Map<Inte
2828
}
2929

3030
/**
31-
* GETTERS for the system
31+
* Gets the username of the user as saved in the database
32+
* @return the username that the user stored
3233
*/
3334
public String getSignedInUsername() {
3435
return username;
3536
}
37+
38+
/**
39+
* Gets whether the user is saved as an admin in the database
40+
* @return the admin level access of the user as stored in the database
41+
*/
3642
public boolean getIsAdmin(){return isAdmin;}
3743

44+
/**
45+
* Gets the list of flashcard set ids belonging to the user and onverts it into a map with the id as
46+
* a key and the title and description of the flashcard set as the value in a string array format
47+
* @return map of the flashcard sets belonging to the user
48+
*/
3849
public Map<Integer, String[]> getFlashcardSets(){
3950

4051
return flashcardSets;

src/main/java/login_and_signup_use_case/UserRegisterInteractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public UserRegisterResponseModel create(UserRegisterRequestModel requestModel) {
4242
// Create a temporary user to access the adminkey
4343
User fakeUser = userFactory.create("BLANK", "BLANK1", false);
4444

45-
// set isAdmin to true if they entered the admin key correctly
45+
// Set isAdmin to true if they entered the admin key correctly
4646
boolean isAdmin = fakeUser.adminKeyValid(requestModel.getAdminKeyEntered());
4747

4848
User user = userFactory.create(requestModel.getName(), requestModel.getPassword(), isAdmin);

src/main/java/login_and_signup_use_case/UserRegisterRequestModel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,34 @@ public UserRegisterRequestModel(String name, String password, String repeatPassw
3030
}
3131

3232
/**
33-
* GETTERS for the UserRegisterRequestModel
33+
* Gets the inputted name that the user opts to be as their username.
34+
* @return the username that the user inputted.
3435
*/
3536
String getName() {
3637
return name;
3738
}
3839

40+
/**
41+
* Gets the inputted password that the user opts to be as their password.
42+
* @return the password that the user inputted.
43+
*/
3944
String getPassword() {
4045
return password;
4146
}
4247

48+
/**
49+
* Gets the inputted repeated password that the user opts to be as their password again to ensure that
50+
* they are sure of the password and that it matches their previously inputted password.
51+
* @return the password that the user inputted.
52+
*/
4353
public String getRepeatPassword() {
4454
return repeatPassword;
4555
}
4656

57+
/**
58+
* Gets the admin key that the user has inputted to check whether they should be given admin level access.
59+
* @return the admin key inputted by the user.
60+
*/
4761
public String getAdminKeyEntered() {
4862
return adminKeyEntered;
4963
}

src/main/java/login_and_signup_use_case/UserRegisterResponseModel.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,25 @@ public UserRegisterResponseModel(String signedUpUsername, String signedUpPasswor
2626
}
2727

2828
/**
29-
* GETTERS for the UserRegisterResponseModel
29+
* Gets the username of the user as it would be saved in the database.
30+
* @return the username assigned to the user for their account.
3031
*/
3132
public String getSignedUpUsername() {
3233
return signedUpUsername;
3334
}
3435

36+
/**
37+
* Gets the password of the user as it would be saved in the database.
38+
* @return the password assigned to the user for their account.
39+
*/
3540
public String getSignedUpPassword(){
3641
return signedUpPassword;
3742
}
43+
44+
/**
45+
* Gets the admin level access of the user as it would be saved in the database.
46+
* @return whether the user is assigned admin level access for their account.
47+
*/
3848
public boolean getIsAdmin(){return isAdmin;}
3949

4050
}

src/test/java/login_and_sign_up_use_case_test/InMemoryUser.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,59 @@
77
import java.util.HashMap;
88
import java.util.Map;
99

10+
/**
11+
* Mock database created in order to test the register test case with a temporary database.
12+
*/
1013
public class InMemoryUser implements IUserDataAccess {
1114

1215
final private Map<String, CommonUserDsRequestModel> users = new HashMap<>();
16+
17+
/**
18+
* Disregarding methods from the actual database classes irrelevant to the mock database.
19+
* @return null since the method isn't applicable to the mock database
20+
*/
1321
@Override
1422
public CommonUserDsRequestModel getUser(String username) {
1523
return null;
1624
}
1725

26+
/**
27+
* Mimic the act of checking whether a user exists in the database.
28+
* @return whether the user exists in the mock database.
29+
*/
1830
@Override
1931
public boolean existsByName(String username) {
2032
return users.containsKey(username);
2133
}
2234

35+
/**
36+
* Disregarding methods from the actual database classes irrelevant to the mock database.
37+
* @return null since the method isn't applicable to the mock database
38+
*/
2339
@Override
2440
public Collection<CommonUserDsRequestModel> getAllUsers() {
2541
return null;
2642
}
2743

44+
/**
45+
* Disregarding methods from the actual database classes irrelevant to the mock database.
46+
*/
2847
@Override
2948
public void saveFlashcardSetID(String username, int FlashcardSetID) {
3049

3150
}
3251

52+
/**
53+
* Disregarding methods from the actual database classes irrelevant to the mock database.
54+
*/
3355
@Override
3456
public void deleteFlashcardSetID(String username, int FlashcardSetID) {
3557

3658
}
3759

60+
/**
61+
* Mimic the act of saving a user as the database
62+
*/
3863
@Override
3964
public void saveUser(CommonUserDsRequestModel user) {
4065
System.out.println("Save " + user.getUsername());

0 commit comments

Comments
 (0)