Skip to content

Commit 63a59b2

Browse files
committed
java doc for dbgateway
1 parent fa125bc commit 63a59b2

File tree

1 file changed

+98
-11
lines changed

1 file changed

+98
-11
lines changed

src/main/java/frameworks_and_drivers/database/DBGateway.java

Lines changed: 98 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,26 @@ public class DBGateway {
1111
private static final String flashcardPath = "src/data/Flashcards.csv";
1212
private static final String flashcardSetPath = "src/data/FlashcardSets.csv";
1313
private static final String userPath = "src/data/Users.csv";
14-
14+
/**
15+
* The gateway object to access flashcard data
16+
*/
1517
IFlashcardDataAccess flashcardGateway;
18+
/**
19+
* The gateway object to access flashcard set data
20+
*/
1621
IFlashcardSetDataAccess flashcardSetGateway;
22+
/**
23+
* The gateway object to access user data
24+
*/
1725
IUserDataAccess userGateway;
1826

27+
/**
28+
* Creates a DBGateway object which contain gateways to every csv file in the database. This acts as a facade class
29+
* for the other gateways.
30+
* @param flashcardGateway the flashcard gateway object.
31+
* @param flashcardSetGateway the flashcard set gateway object.
32+
* @param userGateway the user gateway object.
33+
*/
1934
public DBGateway(IFlashcardDataAccess flashcardGateway,
2035
IFlashcardSetDataAccess flashcardSetGateway,
2136
IUserDataAccess userGateway){
@@ -24,82 +39,154 @@ public DBGateway(IFlashcardDataAccess flashcardGateway,
2439
this.userGateway = userGateway;
2540
}
2641

27-
42+
/**
43+
* Returns the value for if the user contains the given username.
44+
* @param username the user's username.
45+
* @return true if the user contains the given username.
46+
*/
2847
public boolean existsByName(String username){
2948
return this.userGateway.existsByName(username);
3049
}
3150

51+
/**
52+
* Saves the user.
53+
* @param user the common user request model that will be saved.
54+
*/
3255
public void saveUser(CommonUserDsRequestModel user) {
3356
this.userGateway.saveUser(user);
3457
}
3558

36-
59+
/**
60+
* Saves the flashcard set id into the list of flashcard set ids of the user that created the flashcard set.
61+
* @param flashcardSet the flashcard set request model that will be saved.
62+
* @return the id of the flashcard set
63+
*/
3764
public int saveFlashcardSet(FlashcardSetDsRequestModel flashcardSet) {
3865
int id = this.flashcardSetGateway.saveFlashcardSet(flashcardSet);
3966
this.userGateway.saveFlashcardSetID(flashcardSet.getOwnerUsername(), flashcardSet.getFlashcardSetId());
4067
return id;
4168
}
42-
69+
/**
70+
* Edits the title and description of a flashcard set and saves the given edits.
71+
* @param flashcardSet the flashcard set request model that will be edited.
72+
*/
4373
public void editFlashcardSet(FlashcardSetDsRequestModel flashcardSet){
4474
this.flashcardSetGateway.editTitleAndDescription(flashcardSet);
4575
}
4676

77+
/**
78+
* Deletes the flashcard set id from the owner.
79+
* @param ownerUsername the username of user that created the flashcard set.
80+
* @param flashcardSetID the id of the flashcard set that will be deleted.
81+
*/
4782
public void deleteFlashcardSet(String ownerUsername, int flashcardSetID) {
4883
this.userGateway.deleteFlashcardSetID(ownerUsername, flashcardSetID);
4984
this.flashcardSetGateway.deleteFlashcardSet(flashcardSetID);
5085
}
5186

87+
/**
88+
* Saves the flashcard id to the list of flashcard ids contained in the flashcard set.
89+
* @param flashcard the flashcard request model that will be saved.
90+
* @return the id of the flashcard that is saved.
91+
*/
5292
public int saveFlashcard(FlashcardDsRequestModel flashcard) {
53-
5493
int id = this.flashcardGateway.saveFlashcard(flashcard);
5594
this.flashcardSetGateway.saveFlashcardID(flashcard.getBelongsToId(), id);
5695
return id;
5796
}
5897

98+
/**
99+
* Edits the flashcard and saves the given edits.
100+
* @param flashcard the flashcard request model that will be edited
101+
*/
59102
public void editFlashcard(FlashcardDsRequestModel flashcard){
60103
this.flashcardGateway.editFlashcard(flashcard);
61104
}
62105

106+
/**
107+
* Deletes a flashcard id from a flashcard set and deletes the flashcard from the database.
108+
* @param flashcardSetId the id of the flashcard set.
109+
* @param flashcardId the id of the flashcard that will be deleted.
110+
*/
63111
public void deleteFlashcard(int flashcardSetId, int flashcardId) {
64112
this.flashcardSetGateway.removeFlashcardId(flashcardSetId, flashcardId);
65113
this.flashcardGateway.deleteFlashcard(flashcardId);
66114
}
115+
116+
/**
117+
* Gets the flashcard path to the csv containing all the flashcards.
118+
* @return the flashcard path to the csv containing all the flashcards.
119+
*/
67120
public static String getFlashcardPath() {
68121
return flashcardPath;
69122
}
70-
123+
/**
124+
* Gets the flashcard set path to the csv containing all the flashcard sets.
125+
* @return the flashcard set path to the csv containing all the flashcard sets.
126+
*/
71127
public static String getFlashcardSetPath() {
72128
return flashcardSetPath;
73129
}
74-
130+
/**
131+
* Gets the user path to the csv containing all the users.
132+
* @return the user path to the csv containing all the users.
133+
*/
75134
public static String getUserPath() {
76135
return userPath;
77136
}
78137

138+
/**
139+
* Gets the flashcard containing a given flashcard id.
140+
* @param flashcardId the flashcard id.
141+
* @return the flashcard request model containing a given flashcard id.
142+
*/
79143
public FlashcardDsRequestModel getFlashcard(int flashcardId){
80144
return this.flashcardGateway.getFlashcard(flashcardId);
81145
}
82-
146+
/**
147+
* Gets the flashcard set containing a given flashcard set id.
148+
* @param flashcardSetId the flashcard set id.
149+
* @return the flashcard set request model containing a given flashcard set id.
150+
*/
83151
public FlashcardSetDsRequestModel getFlashcardSet(int flashcardSetId){
84152
return this.flashcardSetGateway.getFlashcardSet(flashcardSetId);
85153
}
86-
154+
/**
155+
* Gets the user containing a given username.
156+
* @param username the user's username.
157+
* @return the common user request model containing a given username.
158+
*/
87159
public CommonUserDsRequestModel getCommonUser(String username){
88160
return this.userGateway.getUser(username);
89161
}
90162

163+
/**
164+
* Gets the flashcard gateway.
165+
* @return the flashcard gateway.
166+
*/
91167
public IFlashcardDataAccess getFlashcardGateway() {
92168
return flashcardGateway;
93169
}
94-
170+
/**
171+
* Gets the flashcard set gateway.
172+
* @return the flashcard set gateway.
173+
*/
95174
public IFlashcardSetDataAccess getFlashcardSetGateway() {
96175
return flashcardSetGateway;
97176
}
98-
177+
/**
178+
* Gets the user gateway.
179+
* @return the user gateway.
180+
*/
99181
public IUserDataAccess getUserGateway() {
100182
return userGateway;
101183
}
102184

185+
/**
186+
* Gets the title and description of a flashcard set containing the given flashcard set id.
187+
* @param flashcardSetId the flashcard set id.
188+
* @return the title and description of a flashcard set containing the given flashcard set id.
189+
*/
103190
public String[] getTitleAndDescription(int flashcardSetId) {
104191
return this.flashcardSetGateway.getTitleAndDescription(flashcardSetId);
105192
}

0 commit comments

Comments
 (0)