Skip to content

Commit 9566266

Browse files
committed
java doc for common user data access
1 parent 6359a86 commit 9566266

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/main/java/frameworks_and_drivers/database/CommonUserDataAccess.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
import java.io.*;
77
import java.util.*;
8+
/**
9+
* Common User Request Model.
10+
* Application Business Rules
11+
* @author Justin Li
12+
*/
813

914
public class CommonUserDataAccess implements IUserDataAccess {
1015
private final File userCsvFile;
@@ -13,6 +18,10 @@ public class CommonUserDataAccess implements IUserDataAccess {
1318

1419
private final Map<String, CommonUserDsRequestModel> accounts = new HashMap<>();
1520

21+
/**
22+
* Creates a common user data access based on the following parameters.
23+
* @param csvPath the csv file pathway to the database.
24+
*/
1625
public CommonUserDataAccess(String csvPath) throws IOException {
1726
userCsvFile = new File(csvPath);
1827

@@ -48,6 +57,9 @@ public CommonUserDataAccess(String csvPath) throws IOException {
4857
reader.close();
4958
}
5059
}
60+
/**
61+
* A private function that is called in the methods below which saves any changes made to a common user.
62+
*/
5163
private void save() {
5264
BufferedWriter writer;
5365
try {
@@ -73,44 +85,67 @@ private void save() {
7385
}
7486

7587
}
88+
/**
89+
* Gets the user object with a given username.
90+
* @param username the user's username.
91+
* @return the user object with the given username.
92+
*/
7693
@Override
7794
public CommonUserDsRequestModel getUser(String username) {
7895
return accounts.get(username);
79-
8096
}
81-
97+
/**
98+
* Gets all the user objects in the database.
99+
* @return all the user objects in the database.
100+
*/
82101
@Override
83102
public Collection<CommonUserDsRequestModel> getAllUsers(){
84103
return accounts.values();
85104
}
86-
105+
/**
106+
* Returns true if a user object containing given username exists.
107+
* @param username the user's username
108+
* @return true if a user object containing given username exists.
109+
*/
87110
@Override
88111
public boolean existsByName(String username) {
89112
return accounts.containsKey(username);
90113

91114
}
115+
/**
116+
* Saves a new flashcard set id into the list of current flashcard set ids that the user has created.
117+
* @param username the user's username
118+
* @param flashcardSetId the id of the flashcard set that the user created.
119+
*/
92120
@Override
93-
public void saveFlashcardSetID(String username, int FlashcardSetID) {
121+
public void saveFlashcardSetID(String username, int flashcardSetId) {
94122
CommonUserDsRequestModel oldUser = accounts.get(username);
95123
List<Integer> newFlashcardSet = new ArrayList<>(oldUser.getFlashcardSetIds());
96-
newFlashcardSet.add(FlashcardSetID);
124+
newFlashcardSet.add(flashcardSetId);
97125
CommonUserDsRequestModel newUser = new CommonUserDsRequestModel(oldUser.getUsername(), oldUser.getPassword(), oldUser.getIsAdmin(), newFlashcardSet);
98126

99127
accounts.put(username, newUser);
100128
save();
101129
}
102-
130+
/**
131+
* Deletes a flashcard set created by a user.
132+
* @param username the user's username
133+
* @param flashcardSetId the id of the flashcard set that will be deleted
134+
*/
103135
@Override
104-
public void deleteFlashcardSetID(String username, int FlashcardSetID) {
136+
public void deleteFlashcardSetID(String username, int flashcardSetId) {
105137
CommonUserDsRequestModel oldUser = accounts.get(username);
106138
List<Integer> newFlashcardSet = new ArrayList<>(oldUser.getFlashcardSetIds());
107-
newFlashcardSet.remove((Object) FlashcardSetID);
139+
newFlashcardSet.remove((Object) flashcardSetId);
108140
CommonUserDsRequestModel newUser = new CommonUserDsRequestModel(oldUser.getUsername(), oldUser.getPassword(), oldUser.getIsAdmin(), newFlashcardSet);
109141

110142
accounts.put(username, newUser);
111143
save();
112144
}
113-
145+
/**
146+
* Saves a newly created user to the database
147+
* @param user the user's username
148+
*/
114149
@Override
115150
public void saveUser(CommonUserDsRequestModel user) {
116151
accounts.put(user.getUsername(), user);

0 commit comments

Comments
 (0)