Skip to content

Commit f903f5b

Browse files
Merge branch 'main' of https://github.com/CSC207-2022F-UofT/course-project-team-bbq into Anthony's_Branch
2 parents cd4769e + 141ef7e commit f903f5b

25 files changed

+881
-241
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ This is a flashcard study application inspired by Quizlet.
1616
- If the user selects the "Log In" option from the welcome screen the user may input their respective username and password, if the username does not match an existing username from the database or incorrect password they shall be warned.
1717

1818
### 2. Create a flashcard or a flashcard set.
19+
- Flashcard Set:
20+
- The user can create a flashcard set by clicking the "Add Flashcard Set" button located on the main page
21+
- Once the button is clicked, the user is taken to the flashcard set creation screen
22+
- The user can then enter a title and description for the flashcard set
23+
- If the user clicks on "Create" with either the title or description missing, the user is alerted to include them
24+
- The user can also make the flashcard set Public (unchecked box) or Private (checked box)
25+
- Note: public flashcard sets are searchable by other users, while private ones are not (unless those users are Admins)
26+
- If the user wishes to cancel the creation, they can do so by clicking "Cancel"
27+
- Upon successful creation, the user is notified that their flashcard set has been created
1928

2029
### 3a. Edit a flashcard set.
2130
- If there are no flashcard sets on the main page, then we cannot edit a flashcard set.
@@ -29,6 +38,14 @@ This is a flashcard study application inspired by Quizlet.
2938
- If there are flashcards, the user can choose which flashcard to edit by clicking the "Edit Flashcard" button. When clicked a window pops up with Term and Definition text prompts for the user to edit. The user cannot change the Term to an empty term.
3039

3140
### 4. Delete a flashcard or a flashcard set.
41+
- Flashcard Set:
42+
- The user can delete a flashcard set by clicking the "Delete" button located inside a flashcard set's options box on the main page
43+
- When the button is clicked, the user is then taken to the flashcard set deletion screen
44+
- On this screen, user can cancel the deletion at any time by clicking the "Cancel" button
45+
- If the user clicks on "Delete", the user is presented with a confirmation dialog box
46+
- Selecting "No" cancels the deletion and selecting "Yes" commences the deletion process
47+
- Note: deleting a flashcard set would also delete all flashcards contained within that set
48+
- Upon successful deletion, the user is notified that their flashcard set has been deleted
3249

3350
### 5. Search for a public flashcard set.
3451
- If the user selects the search button from the main page the user can search through the public community database for flashcard sets

src/main/java/create_flashcard_use_case/CreateFlashcardInputBoundary.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
public interface CreateFlashcardInputBoundary {
1010
CreateFlashcardResponseModel create(CreateFlashcardRequestModel requestModel);
11+
CreateFlashcardResponseModel create(CreateFlashcardRequestModel requestModel, int flashcardId);
12+
1113

1214
}
Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package create_flashcard_use_case;
2-
32
import frameworks_and_drivers.database.DBGateway;
4-
import data_access_use_case.IFlashcardDataAccess;
5-
import data_access_use_case.IFlashcardSetDataAccess;
63
import data_access_use_case.entity_request_models.FlashcardDsRequestModel;
74

85
import java.time.LocalDateTime;
@@ -13,40 +10,70 @@
1310
*/
1411
public class CreateFlashcardInteractor implements CreateFlashcardInputBoundary {
1512
CreateFlashcardOutputBoundary presenter;
16-
IFlashcardDataAccess fcDataAccess;
17-
IFlashcardSetDataAccess fcsDataAccess;
13+
DBGateway gateway;
1814

1915
/**
20-
* Create FcCInteractor
16+
* Create CreateFlashcardInteractor
2117
* @param gateway Database gateway.
2218
* @param presenter Presenter for failure or success view.
2319
*/
2420
public CreateFlashcardInteractor(DBGateway gateway, CreateFlashcardOutputBoundary presenter){
2521
this.presenter = presenter;
26-
this.fcDataAccess = gateway.getFlashcardGateway();
27-
this.fcsDataAccess = gateway.getFlashcardSetGateway();
22+
this.gateway = gateway;
2823
}
2924

3025
/**
31-
* Create flashcard with given term, definition in the given flashcard set recording the date of creation.
32-
* If term or definition is empty flashcard set does not exist, returns the corresponding error.
26+
* Try to create a flashcard with the given term and definition in the given flashcard set, recording the date of creation.
27+
* If the term or definition is empty flashcard set does not exist, return the corresponding error.
28+
* If there is already a flashcard with the same term, return the response model representing the existing flashcard.
3329
* @return Success or failure view.
3430
*/
3531
@Override
3632
public CreateFlashcardResponseModel create(CreateFlashcardRequestModel requestModel) {
37-
if(requestModel.getDefinition().isEmpty()||requestModel.getTerm().isEmpty()){
33+
String term = requestModel.getTerm().replace("\n", " ").trim();
34+
String definition = requestModel.getDefinition().replace("\n", " ").trim();
35+
if(term.isEmpty() || definition.isEmpty()){
3836
return presenter.prepareFailView("Term or definition is empty.");
39-
} else if (fcsDataAccess.getFlashcardSet(requestModel.getFlashcardSetId()) == null) {
37+
}
38+
else if (gateway.getFlashcardSet(requestModel.getFlashcardSetId()) == null) {
4039
return presenter.prepareFailView("Flashcard set does not exist.");
4140
}
41+
for (int flashcardId : gateway.getFlashcardSet(requestModel.getFlashcardSetId()).getFlashcardIds()){
42+
if (gateway.getFlashcard(flashcardId).getTerm().equals(term)){
43+
return presenter.prepareDuplicateView(new CreateFlashcardResponseModel(LocalDateTime.now(), requestModel.getTerm(),
44+
gateway.getFlashcard(flashcardId).getDefinition(), flashcardId, true));
45+
}
46+
}
4247
LocalDateTime creationDate = LocalDateTime.now();
43-
FlashcardDsRequestModel flashcard = new FlashcardDsRequestModel(
44-
requestModel.getTerm().replace("\n", " "),
45-
requestModel.getDefinition().replace("\n", " "), creationDate,-1, requestModel.getFlashcardSetId());
46-
int flashcardId = fcDataAccess.saveFlashcard(flashcard);
47-
fcsDataAccess.saveFlashcardID(requestModel.getFlashcardSetId(), flashcardId);
48+
int flashcardId = gateway.saveFlashcard(new FlashcardDsRequestModel(term, definition, creationDate, -1,
49+
requestModel.getFlashcardSetId()));
50+
return presenter.prepareSuccessView(new
51+
CreateFlashcardResponseModel(creationDate, term, definition, flashcardId, false));
4852

49-
return presenter.prepareSuccessView(new CreateFlashcardResponseModel(creationDate, requestModel.getTerm(),
50-
requestModel.getDefinition()));
53+
}
54+
55+
56+
/**
57+
* Try to create a flashcard with the given term and definition in the given flashcard set,
58+
* overwrite the flashcard at flashcardId.
59+
* If the term or definition is empty flashcard set does not exist, return the corresponding error.
60+
* If there is already a flashcard with the same term, return the response model representing the existing flashcard.
61+
* @param requestModel request model
62+
* @param flashcardId flashcardId for the method to overwrite
63+
* @return success or failure view
64+
*/
65+
public CreateFlashcardResponseModel create(CreateFlashcardRequestModel requestModel, int flashcardId){
66+
String term = requestModel.getTerm().replace("\n", " ").trim();
67+
String definition = requestModel.getDefinition().replace("\n", " ").trim();
68+
if(term.isEmpty() || definition.isEmpty()){
69+
return presenter.prepareFailView("Term or definition is empty.");
70+
}
71+
else if (gateway.getFlashcardSet(requestModel.getFlashcardSetId()) == null) {
72+
return presenter.prepareFailView("Flashcard set does not exist.");
73+
}
74+
LocalDateTime creationDate = LocalDateTime.now();
75+
gateway.editFlashcard(new FlashcardDsRequestModel(term, definition, creationDate, flashcardId,
76+
requestModel.getFlashcardSetId()));
77+
return new CreateFlashcardResponseModel(creationDate, term, definition, flashcardId,false);
5178
}
5279
}

src/main/java/create_flashcard_use_case/CreateFlashcardOutputBoundary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*/
77
public interface CreateFlashcardOutputBoundary {
88
CreateFlashcardResponseModel prepareSuccessView(CreateFlashcardResponseModel responseModel);
9-
109
CreateFlashcardResponseModel prepareFailView(String error);
10+
CreateFlashcardResponseModel prepareDuplicateView(CreateFlashcardResponseModel responseModel);
1111
}

src/main/java/create_flashcard_use_case/CreateFlashcardRequestModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CreateFlashcardRequestModel {
1111
private String term, definition;
1212

1313
/**
14-
* Create FcCRequestModel
14+
* Create CreateFlashcardRequestModel
1515
* @param flashcardSetId id of flashcard set which new flashcard will be added to
1616
* @param term term of the flashcard
1717
* @param definition definition of the flashcard

src/main/java/create_flashcard_use_case/CreateFlashcardResponseModel.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@
99
public class CreateFlashcardResponseModel {
1010
private final LocalDateTime creationDate;
1111
private String term, definition;
12+
private int flashcardId;
13+
private final Boolean existsDuplicate;
1214

1315
/**
14-
* Create FcCResponseModel
15-
* @param creationDate date of creation of the flashcard
16+
*Create CreateFlashcardResponseModel for flashcard creation
17+
* @param creationDate date of creation
1618
* @param term term of the flashcard
1719
* @param definition definition of the flashcard
20+
* @param flashcardId flashcard id of the flashcard
21+
* @param existsDuplicate if there is a duplicate flashcard currently
1822
*/
19-
public CreateFlashcardResponseModel(LocalDateTime creationDate, String term, String definition) {
23+
public CreateFlashcardResponseModel(LocalDateTime creationDate, String term, String definition, int flashcardId, Boolean existsDuplicate) {
2024
this.creationDate = creationDate;
2125
this.term = term;
2226
this.definition = definition;
27+
this.flashcardId = flashcardId;
28+
this.existsDuplicate = existsDuplicate;
29+
2330
}
2431

2532
public void setDefinition(String definition) {
@@ -30,6 +37,10 @@ public void setTerm(String term) {
3037
this.term = term;
3138
}
3239

40+
public void setFlashcardId(int flashcardId) {
41+
this.flashcardId = flashcardId;
42+
}
43+
3344
public String getDefinition() {
3445
return definition;
3546
}
@@ -41,4 +52,12 @@ public String getTerm() {
4152
public LocalDateTime getCreationDate() {
4253
return creationDate;
4354
}
55+
56+
public int getFlashcardId() {
57+
return flashcardId;
58+
}
59+
60+
public Boolean existsDuplicate() {
61+
return existsDuplicate;
62+
}
4463
}
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
11
package data_access_use_case.entity_request_models;
22

33
import java.util.List;
4+
/**
5+
* Common User Request Model.
6+
* Application Business Rules
7+
* @author Justin Li
8+
*/
49

510
public class CommonUserDsRequestModel {
611
private final String username;
712
private final String password;
813
private final boolean isAdmin;
914
private final List<Integer> flashcardSetIds;
1015

16+
/**
17+
* Creates a flashcard response model based on the following parameters.
18+
* @param username the user's username.
19+
* @param password the user's password.
20+
* @param isAdmin true if the user is an admin user.
21+
* @param flashcardSetIds the list of flashcard set ids created by the user.
22+
*/
1123
public CommonUserDsRequestModel(String username, String password, boolean isAdmin, List<Integer> flashcardSetIds){
1224
this.username = username;
1325
this.password = password;
1426
this.isAdmin = isAdmin;
1527
this.flashcardSetIds = flashcardSetIds;
1628
}
29+
30+
/**
31+
* Gets the username of the user
32+
* @return the username of the user
33+
*/
1734
public String getUsername(){
1835
return username;
1936
}
20-
37+
/**
38+
* Gets the password of the user
39+
* @return the password of the user
40+
*/
2141
public String getPassword(){
2242
return password;
2343
}
24-
44+
/**
45+
* Gets if the user is an admin user
46+
* @return true if the user is an admin user.
47+
*/
2548
public boolean getIsAdmin(){
2649
return isAdmin;
2750
}
28-
51+
/**
52+
* Gets the list of flashcard set ids created by the user
53+
* @return the list of flashcard set ids created by the user
54+
*/
2955
public List<Integer> getFlashcardSetIds(){
30-
return flashcardSetIds ;
56+
return flashcardSetIds;
3157
}
3258
}

src/main/java/data_access_use_case/entity_request_models/FlashcardDsRequestModel.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package data_access_use_case.entity_request_models;
2-
// use case layer
32

43
import java.time.LocalDateTime;
4+
/**
5+
* Flashcard Request Model.
6+
* Application Business Rules
7+
* @author Justin Li
8+
*/
59

610
public class FlashcardDsRequestModel {
711
private String term;
@@ -10,6 +14,14 @@ public class FlashcardDsRequestModel {
1014
private int flashcardId;
1115
private final int belongsToId;
1216

17+
/**
18+
* Creates a flashcard response model based on the following parameters.
19+
* @param term the flashcard term
20+
* @param definition the flashcard definition for the term
21+
* @param creationDate the time the flashcard is created (time formatted in LocalDateTime)
22+
* @param flashcardId the flashcard id
23+
* @param belongsToId the id of the flashcard set that the flashcard is in.
24+
*/
1325
public FlashcardDsRequestModel(String term, String definition, LocalDateTime creationDate,
1426
int flashcardId, int belongsToId){
1527
this.term = term;
@@ -18,33 +30,54 @@ public FlashcardDsRequestModel(String term, String definition, LocalDateTime cre
1830
this.flashcardId = flashcardId;
1931
this.belongsToId = belongsToId;
2032
}
33+
/**
34+
* Gets the flashcard term.
35+
* @return the flashcard term
36+
*/
2137
public String getTerm() {
2238
return term;
2339
}
24-
40+
/**
41+
* Gets the flashcard definition.
42+
* @return the flashcard definition.
43+
*/
2544
public String getDefinition() {
2645
return definition;
2746
}
28-
47+
/**
48+
* Gets the flashcard creation date.
49+
* @return the flashcard creation date in LocalDateTime formatting.
50+
*/
2951
public LocalDateTime getCreationDate() {
3052
return creationDate;
3153
}
32-
54+
/**
55+
* Gets the flashcard id.
56+
* @return the flashcard id.
57+
*/
3358
public int getFlashcardId(){
3459
return flashcardId;
3560
}
36-
61+
/**
62+
* Gets the id of the flashcard set that the flashcard belongs to.
63+
* @return the id of the flashcard set that the flashcard belongs to.
64+
*/
3765
public int getBelongsToId(){
3866
return belongsToId;
3967
}
40-
public void setTerm(String term) {
41-
this.term = term;
42-
}
43-
68+
/**
69+
* Sets the term.
70+
*/
71+
public void setTerm(String term) {this.term = term;}
72+
/**
73+
* Sets the definition.
74+
*/
4475
public void setDefinition(String definition) {
4576
this.definition = definition;
4677
}
47-
78+
/**
79+
* Sets the flashcard id.
80+
*/
4881
public void setFlashcardId(int flashcardId) {
4982
this.flashcardId = flashcardId;
5083
}

0 commit comments

Comments
 (0)