@@ -11,11 +11,26 @@ public class DBGateway {
11
11
private static final String flashcardPath = "src/data/Flashcards.csv" ;
12
12
private static final String flashcardSetPath = "src/data/FlashcardSets.csv" ;
13
13
private static final String userPath = "src/data/Users.csv" ;
14
-
14
+ /**
15
+ * The gateway object to access flashcard data
16
+ */
15
17
IFlashcardDataAccess flashcardGateway ;
18
+ /**
19
+ * The gateway object to access flashcard set data
20
+ */
16
21
IFlashcardSetDataAccess flashcardSetGateway ;
22
+ /**
23
+ * The gateway object to access user data
24
+ */
17
25
IUserDataAccess userGateway ;
18
26
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
+ */
19
34
public DBGateway (IFlashcardDataAccess flashcardGateway ,
20
35
IFlashcardSetDataAccess flashcardSetGateway ,
21
36
IUserDataAccess userGateway ){
@@ -24,82 +39,154 @@ public DBGateway(IFlashcardDataAccess flashcardGateway,
24
39
this .userGateway = userGateway ;
25
40
}
26
41
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
+ */
28
47
public boolean existsByName (String username ){
29
48
return this .userGateway .existsByName (username );
30
49
}
31
50
51
+ /**
52
+ * Saves the user.
53
+ * @param user the common user request model that will be saved.
54
+ */
32
55
public void saveUser (CommonUserDsRequestModel user ) {
33
56
this .userGateway .saveUser (user );
34
57
}
35
58
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
+ */
37
64
public int saveFlashcardSet (FlashcardSetDsRequestModel flashcardSet ) {
38
65
int id = this .flashcardSetGateway .saveFlashcardSet (flashcardSet );
39
66
this .userGateway .saveFlashcardSetID (flashcardSet .getOwnerUsername (), flashcardSet .getFlashcardSetId ());
40
67
return id ;
41
68
}
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
+ */
43
73
public void editFlashcardSet (FlashcardSetDsRequestModel flashcardSet ){
44
74
this .flashcardSetGateway .editTitleAndDescription (flashcardSet );
45
75
}
46
76
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
+ */
47
82
public void deleteFlashcardSet (String ownerUsername , int flashcardSetID ) {
48
83
this .userGateway .deleteFlashcardSetID (ownerUsername , flashcardSetID );
49
84
this .flashcardSetGateway .deleteFlashcardSet (flashcardSetID );
50
85
}
51
86
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
+ */
52
92
public int saveFlashcard (FlashcardDsRequestModel flashcard ) {
53
-
54
93
int id = this .flashcardGateway .saveFlashcard (flashcard );
55
94
this .flashcardSetGateway .saveFlashcardID (flashcard .getBelongsToId (), id );
56
95
return id ;
57
96
}
58
97
98
+ /**
99
+ * Edits the flashcard and saves the given edits.
100
+ * @param flashcard the flashcard request model that will be edited
101
+ */
59
102
public void editFlashcard (FlashcardDsRequestModel flashcard ){
60
103
this .flashcardGateway .editFlashcard (flashcard );
61
104
}
62
105
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
+ */
63
111
public void deleteFlashcard (int flashcardSetId , int flashcardId ) {
64
112
this .flashcardSetGateway .removeFlashcardId (flashcardSetId , flashcardId );
65
113
this .flashcardGateway .deleteFlashcard (flashcardId );
66
114
}
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
+ */
67
120
public static String getFlashcardPath () {
68
121
return flashcardPath ;
69
122
}
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
+ */
71
127
public static String getFlashcardSetPath () {
72
128
return flashcardSetPath ;
73
129
}
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
+ */
75
134
public static String getUserPath () {
76
135
return userPath ;
77
136
}
78
137
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
+ */
79
143
public FlashcardDsRequestModel getFlashcard (int flashcardId ){
80
144
return this .flashcardGateway .getFlashcard (flashcardId );
81
145
}
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
+ */
83
151
public FlashcardSetDsRequestModel getFlashcardSet (int flashcardSetId ){
84
152
return this .flashcardSetGateway .getFlashcardSet (flashcardSetId );
85
153
}
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
+ */
87
159
public CommonUserDsRequestModel getCommonUser (String username ){
88
160
return this .userGateway .getUser (username );
89
161
}
90
162
163
+ /**
164
+ * Gets the flashcard gateway.
165
+ * @return the flashcard gateway.
166
+ */
91
167
public IFlashcardDataAccess getFlashcardGateway () {
92
168
return flashcardGateway ;
93
169
}
94
-
170
+ /**
171
+ * Gets the flashcard set gateway.
172
+ * @return the flashcard set gateway.
173
+ */
95
174
public IFlashcardSetDataAccess getFlashcardSetGateway () {
96
175
return flashcardSetGateway ;
97
176
}
98
-
177
+ /**
178
+ * Gets the user gateway.
179
+ * @return the user gateway.
180
+ */
99
181
public IUserDataAccess getUserGateway () {
100
182
return userGateway ;
101
183
}
102
184
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
+ */
103
190
public String [] getTitleAndDescription (int flashcardSetId ) {
104
191
return this .flashcardSetGateway .getTitleAndDescription (flashcardSetId );
105
192
}
0 commit comments