Skip to content

Commit 396c649

Browse files
Merge branch 'main' of https://github.com/CSC207-2022F-UofT/course-project-team-bbq into feature-edit-main-page
# Conflicts: # src/data/FlashcardSets.csv
2 parents 7257e06 + 141ef7e commit 396c649

File tree

222 files changed

+5082
-2661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+5082
-2661
lines changed

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,64 @@ This is a flashcard study application inspired by Quizlet.
44

55
# Main Features
66

7-
### 1. Log in or sign up for the application.
7+
### 1a. Sign Up For The Application.
8+
- If the user selects the "Sign Up" option from the welcome screen the user has an option of Signing up as a user with or without admin level access
9+
- The user must select a username that does not previously exist in the database, if the user inputs a previously existing username they shall be warned with a failure in registration and must choose another username.
10+
- The password needs to be greater than or equal to 5 characters in length and not blank.
11+
- The repeat password must match the password entered to ensure coherency and surety.
12+
- If the user does not require admin level they can leave the Admin Key field blank and they shall be registered as a common user that can access teh program.
13+
- If the user does require admin level access they can input the Admin Key in the field, if there is an error in the inputting of the key the user shall be warned accordingly.
14+
15+
### 1b. Log In For The Application.
16+
- 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.
817

918
### 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
1028

11-
### 3. Edit a flashcard or a flashcard set.
29+
### 3a. Edit a flashcard set.
30+
- If there are no flashcard sets on the main page, then we cannot edit a flashcard set.
31+
- If there is a flashcard set, the user can choose which flashcard set to edit and can click the "Edit" button of the desired flashcard set.
32+
- When "Edit" is clicked an Editor Main Page is shown. There is an "Edit Flashcard Set" button and when clicked a window pops up with Title and Description text prompts for the user to edit. The user cannot change the Title to an empty title.
33+
### 3b. Edit a flashcard in a flashcard set.
34+
- If there are no flashcard sets on the main page, then we cannot edit a flashcard in a flashcard set.
35+
- If there is a flashcard set, the user can choose which flashcard set to edit and can click the "Edit" button of the desired flashcard set.
36+
- When "Edit" is clicked an Editor Main Page is shown.
37+
- If there are no flashcards, the user cannot edit a flashcard.
38+
- 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.
1239

1340
### 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
1449

1550
### 5. Search for a public flashcard set.
51+
- If the user selects the search button from the main page the user can search through the public community database for flashcard sets
52+
- The user types in search input, and selects tags to search from (title, description, owner), or optionally they can choose to “search all”
53+
- The user will be taken to a results screen where a list of all the public flashcard sets matching the user’s search will be returned, displaying the title, description, and creator for each
54+
- If the user is an admin, a list of all flashcard sets will be returned, regardless if the flashcard set is public or private
55+
- Once the user is on the results screen they are able to study or take a quiz for each flashcard set
56+
- If the user is an admin they also have the ability to edit and delete every flashcard set in the results
1657

1758
### 6. Study from a flashcard set.
18-
59+
- Given a flashcard set, the user can enter study mode
60+
- The user can choose how to sort the flashcard set: by creation date, by alphabetical order, or by random shuffle
61+
- The user can choose if they want to view the cards in order or in reverse order
62+
- The user can choose if the flashcard displays terms or definition by default
63+
- The user is then presented with the first flashcard in the flashcard set, given their sorting preferences. The user can choose to
64+
flip the flashcard, go to the next card, or go to the previous card until they wish to quit studying
1965
### 7. Generate and take a quiz from a flashcard set.
2066
- Given a flashcard set, the user can enter quiz mode.
2167
- Quiz mode features three types of questions: multiple choice, text entry, and true/false.

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ repositories {
77
}
88

99
dependencies {
10-
implementation 'junit:junit:4.13.1'
11-
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')
10+
implementation 'junit:junit:4.13.2'
11+
testImplementation('org.junit.jupiter:junit-jupiter:5.9.0')
1212
implementation 'com.formdev:flatlaf:2.6'
1313
}
1414

src/data/FlashcardSets.csv

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
title,description,isPrivate,flashcardSetId,ownerUsername,flashcardIds
2-
test set 1,for testing study use case,false,0,testUser,[0, 1, 2, 3],0,1,2,3
3-
empty test set,for testing study use case with empty set,true,1,testUser,[]
4-
Long Test Set,Insert Generic Description,false,2,testUser,[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],10,11,12,13,14,15,16,17,18,19,20,21
5-
SPA100,Beginner Spanish,true,3,tomomot,[]
2+
test set 1,for testing study use case,false,0,testUser,0,1,2,3
3+
empty test set,for testing study use case with empty set,true,1,testUser
4+
Long Test Set,Insert Generic Description,false,2,Anthony,10,11,12,13,14,15,16,17,18,19,20,21

src/main/java/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import com.formdev.flatlaf.FlatDarculaLaf;
22

3-
import login_and_signup_use_case.login_and_signup_use_case_screens.WelcomeScreen;
3+
import frameworks_and_drivers.screens.WelcomeScreen;
44

55
import java.io.IOException;
66

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package create_flashcard_set_use_case;
2+
3+
// Use case (Red) layer
4+
5+
import interface_adapters.presenters.exceptions.CreateFlashcardSetFailed;
6+
7+
/**
8+
* The input boundary interface for creating flashcard sets.
9+
*
10+
* @author Edward Ishii
11+
*/
12+
13+
public interface CreateFlashcardSetInputBoundary {
14+
15+
/**
16+
* Create a new flashcard set and store it into the database.
17+
*
18+
* @param requestModel the request model required for flashcard set creation.
19+
* @return the response model containing the newly created flashcard set data.
20+
*/
21+
CreateFlashcardSetResponseModel create(CreateFlashcardSetRequestModel requestModel) throws CreateFlashcardSetFailed;
22+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package create_flashcard_set_use_case;
2+
3+
import frameworks_and_drivers.database.DBGateway;
4+
import data_access_use_case.IFlashcardSetDataAccess;
5+
import data_access_use_case.entity_request_models.FlashcardSetDsRequestModel;
6+
import entities.FlashcardSet;
7+
import entities.FlashcardSetFactory;
8+
import interface_adapters.presenters.exceptions.CreateFlashcardSetFailed;
9+
10+
import java.util.ArrayList;
11+
import java.util.Objects;
12+
13+
// Use case (Red) layer
14+
15+
/**
16+
* [Feature 3: Creating a Flashcard Set]
17+
* UI:
18+
* - user enters title and description of flashcard set
19+
* - user also enters their username (for ownerUsername parameter in data access request model)
20+
* - user clicks on button to indicate public or private
21+
* - user clicks on button to either create or discard the flashcard set
22+
* Use case:
23+
* - check that the flashcard set contains a title, description, and owner's username (if not, alert user)
24+
* - create and store newly created flashcard set
25+
* - notify successful creation of flashcard set to user
26+
*
27+
* @author Edward Ishii
28+
*/
29+
public class CreateFlashcardSetInteractor implements CreateFlashcardSetInputBoundary {
30+
DBGateway dbGateway;
31+
IFlashcardSetDataAccess flashcardSetDataAccess; // for testing
32+
CreateFlashcardSetOutputBoundary createFlashcardSetOutputBoundary;
33+
FlashcardSetFactory flashcardSetFactory;
34+
35+
/**
36+
* Constructs the use case interactor.
37+
*
38+
* @param dbGateway the database to store the flashcard set in.
39+
* @param createFlashcardSetOutputBoundary the output boundary for preparing success/fail view of saving flashcard sets.
40+
* @param flashcardSetFactory the factory that creates flashcard sets.
41+
*/
42+
public CreateFlashcardSetInteractor(DBGateway dbGateway, CreateFlashcardSetOutputBoundary createFlashcardSetOutputBoundary,
43+
FlashcardSetFactory flashcardSetFactory) {
44+
this.dbGateway = dbGateway;
45+
this.createFlashcardSetOutputBoundary = createFlashcardSetOutputBoundary;
46+
this.flashcardSetFactory = flashcardSetFactory;
47+
}
48+
49+
/**
50+
* Alternative constructor for testing purposes.
51+
*
52+
* @param flashcardSetDataAccess the flashcard set database.
53+
* @param createFlashcardSetOutputBoundary the output boundary for preparing success/fail view.
54+
* @param flashcardSetFactory the factory creating flashcard sets.
55+
*/
56+
public CreateFlashcardSetInteractor(IFlashcardSetDataAccess flashcardSetDataAccess,
57+
CreateFlashcardSetOutputBoundary createFlashcardSetOutputBoundary,
58+
FlashcardSetFactory flashcardSetFactory) {
59+
this.flashcardSetDataAccess = flashcardSetDataAccess;
60+
this.createFlashcardSetOutputBoundary = createFlashcardSetOutputBoundary;
61+
this.flashcardSetFactory = flashcardSetFactory;
62+
}
63+
64+
/**
65+
* Creates a flashcard set and stores it into the database.
66+
*
67+
* @param inputData the request model containing data required for creating flashcard sets.
68+
* @return the response model containing the newly created flashcard set data.
69+
* @throws CreateFlashcardSetFailed the error thrown if flashcard set creation fails.
70+
*/
71+
@Override
72+
public CreateFlashcardSetResponseModel create(CreateFlashcardSetRequestModel inputData) throws CreateFlashcardSetFailed {
73+
74+
// I chose to throw an exception when user gives invalid input so that the UI layer or any other caller
75+
// can use try-catch block to handle when to alert the user that something went wrong during creation.
76+
77+
// throw exception if title, description, or username is missing
78+
if (Objects.equals(inputData.getTitle(), "")) {
79+
return createFlashcardSetOutputBoundary.prepareFailView("Title is missing!");
80+
} else if (Objects.equals(inputData.getDescription(), "")) {
81+
return createFlashcardSetOutputBoundary.prepareFailView("Description is missing!");
82+
} else if (Objects.equals(inputData.getUsername(), "")) {
83+
return createFlashcardSetOutputBoundary.prepareFailView("Username is missing!");
84+
}
85+
86+
int tempFlashcardSetId = -1; // placeholder id
87+
88+
// create the flashcard set
89+
FlashcardSetFactory factory = new FlashcardSetFactory();
90+
FlashcardSet fs = factory.create(inputData.getTitle(), inputData.getDescription(),
91+
inputData.isPrivate(), tempFlashcardSetId, inputData.getUsername());
92+
93+
// store the flashcard set into database
94+
ArrayList<Integer> flashcardIds = new ArrayList<>(); // set starts with empty list of flashcard ids
95+
FlashcardSetDsRequestModel dsRequestModel = new FlashcardSetDsRequestModel(fs.getTitle(), fs.getDescription(),
96+
fs.getIsPrivate(), tempFlashcardSetId, fs.getOwnerUsername(), flashcardIds);
97+
98+
try {
99+
int savedFlashcardSetId = dbGateway.saveFlashcardSet(dsRequestModel);
100+
101+
// create the saved flashcard set with its proper id
102+
FlashcardSet savedFs = factory.create(inputData.getTitle(), inputData.getDescription(),
103+
inputData.isPrivate(), savedFlashcardSetId, inputData.getUsername());
104+
105+
CreateFlashcardSetResponseModel responseModel = new CreateFlashcardSetResponseModel(savedFs);
106+
107+
return createFlashcardSetOutputBoundary.prepareSuccessView(responseModel);
108+
} catch (NullPointerException e) {
109+
return null;
110+
}
111+
112+
}
113+
114+
115+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package create_flashcard_set_use_case;
2+
3+
// Use case (Red) layer
4+
5+
import interface_adapters.presenters.exceptions.CreateFlashcardSetFailed;
6+
7+
/**
8+
* The output boundary interface that updates the view when creating a flashcard set succeeds or fails.
9+
*
10+
* @author Edward Ishii
11+
*/
12+
13+
public interface CreateFlashcardSetOutputBoundary {
14+
/**
15+
* Prepares the success view when a flashcard set is created and saved.
16+
*
17+
* @param fs the flashcard set that has been created.
18+
* @return the response model containing the saved flashcard set data.
19+
*/
20+
CreateFlashcardSetResponseModel prepareSuccessView(CreateFlashcardSetResponseModel fs);
21+
22+
/**
23+
* Prepares the fail view when a flashcard set cannot be created or saved.
24+
*
25+
* @param error the failure message.
26+
* @return the response model containing the failure message.
27+
* @throws CreateFlashcardSetFailed the error thrown when flashcard set creation fails.
28+
*/
29+
CreateFlashcardSetResponseModel prepareFailView(String error) throws CreateFlashcardSetFailed;
30+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package create_flashcard_set_use_case;
2+
3+
// Use case (Red) layer
4+
5+
/**
6+
* The request model required for creating a flashcard set.
7+
*
8+
* @author Edward Ishii
9+
*/
10+
public class CreateFlashcardSetRequestModel {
11+
private String title;
12+
private String description;
13+
private boolean isPrivate;
14+
private String username;
15+
16+
/**
17+
* Constructs the request model.
18+
*
19+
* @param title the title of the flashcard set.
20+
* @param description the description of the flashcard set.
21+
* @param isPrivate the privacy of the flashcard set.
22+
* @param username the owner's username of the flashcard set.
23+
*/
24+
public CreateFlashcardSetRequestModel(String title, String description, boolean isPrivate, String username) {
25+
this.title = title;
26+
this.description = description;
27+
this.isPrivate = isPrivate;
28+
this.username = username;
29+
}
30+
31+
/**
32+
* Getter for the flashcard set title.
33+
*
34+
* @return the title of this flashcard set.
35+
*/
36+
public String getTitle() {
37+
return title;
38+
}
39+
40+
/**
41+
* Setter for the flashcard set title.
42+
*
43+
* @param title the new title for this flashcard set.
44+
*/
45+
public void setTitle(String title) {
46+
this.title = title;
47+
}
48+
49+
/**
50+
* Getter for the description of the flashcard set.
51+
*
52+
* @return the description of this flashcard set.
53+
*/
54+
public String getDescription() {
55+
return description;
56+
}
57+
58+
/**
59+
* Setter for the description of the flashcard set.
60+
*
61+
* @param description the new description for this flashcard set.
62+
*/
63+
public void setDescription(String description) {
64+
this.description = description;
65+
}
66+
67+
/**
68+
* Getter for the privacy of the flashcard set.
69+
*
70+
* @return the privacy of this flashcard set.
71+
*/
72+
public boolean isPrivate() {
73+
return isPrivate;
74+
}
75+
76+
/**
77+
* Setter for the privacy of the flashcard set.
78+
*
79+
* @param aPrivate the new privacy status for this flashcard set.
80+
*/
81+
public void setPrivate(boolean aPrivate) {
82+
isPrivate = aPrivate;
83+
}
84+
85+
/**
86+
* Getter for the owner's username of the flashcard set.
87+
*
88+
* @return the owner's username of this flashcard set.
89+
*/
90+
public String getUsername() {
91+
return username;
92+
}
93+
94+
/**
95+
* Setter for the owner's username of the flashcard set.
96+
*
97+
* @param username the new owner's username of this flashcard set.
98+
*/
99+
public void setUsername(String username) {
100+
this.username = username;
101+
}
102+
103+
}

0 commit comments

Comments
 (0)