Skip to content

Commit 20273b6

Browse files
committed
Merge branch 'main' of https://github.com/CSC207-2022F-UofT/course-project-team-bbq into 8-feature-main-home-page
2 parents 12a2371 + 4fc9299 commit 20273b6

File tree

64 files changed

+1015
-383
lines changed

Some content is hidden

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

64 files changed

+1015
-383
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/main/java/create_flashcard_set_use_case/CreationScreen.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package create_flashcard_set_use_case;
22

33
import login_and_signup_use_case.UserLoginResponseModel;
4-
import view.Screen;
54

65
import javax.swing.*;
76
import java.awt.*;
@@ -11,13 +10,18 @@
1110

1211
// Frameworks/Drivers (Blue) layer
1312

14-
public class CreationScreen extends Screen implements ActionListener {
13+
/**
14+
* The flashcard set creation screen.
15+
*
16+
* @author Edward Ishii
17+
*/
18+
public class CreationScreen extends JFrame implements ActionListener {
1519
/**
16-
* The title of the flashcard set chosen by the user
20+
* The title of the flashcard set chosen by the user.
1721
*/
1822
JTextField title = new JTextField(15);
1923
/**
20-
* The description of the flashcard set
24+
* The description of the flashcard set.
2125
*/
2226
JTextField description = new JTextField(15);
2327
// /**
@@ -26,10 +30,13 @@ public class CreationScreen extends Screen implements ActionListener {
2630
// JTextField username = new JTextField(15);
2731

2832
/**
29-
* The controller
33+
* The controller.
3034
*/
3135
FlashcardSetController flashcardSetController;
3236

37+
/**
38+
* The user.
39+
*/
3340
UserLoginResponseModel user;
3441

3542
private boolean privateSelected; // for public or private status of flashcard set
@@ -93,10 +100,10 @@ public void actionPerformed(ActionEvent evt) {
93100
privateSelected = !privateSelected; // toggle every time clicked
94101
} else {
95102
try {
96-
flashcardSetController.create(title.getText(), description.getText(),
97-
privateSelected, user.getSignedInUsername());
103+
FlashcardSetResponseModel responseModel = flashcardSetController.create(title.getText(),
104+
description.getText(), privateSelected, user.getSignedInUsername());
98105
JOptionPane.showMessageDialog(this,
99-
String.format("Flashcard Set: [%s] created.", title.getText()));
106+
String.format("Flashcard Set: [%s] has been created.", responseModel.getFs().getTitle()));
100107
this.dispose(); // exit creation screen
101108
} catch (FlashcardSetCreationFailed e) {
102109
JOptionPane.showMessageDialog(this, e.getMessage());

src/main/java/create_flashcard_set_use_case/FlashcardSetController.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,37 @@
22

33
// Interface adapters (Green) layer
44

5+
/**
6+
* The controller for flashcard set creation.
7+
*
8+
* @author Edward Ishii
9+
*/
510
public class FlashcardSetController {
611

7-
FlashcardSetInputBoundary userInput;
12+
FlashcardSetInputBoundary interactor;
813

9-
public FlashcardSetController(FlashcardSetInputBoundary userInput) {
10-
this.userInput = userInput;
14+
/**
15+
* Constructs a new FlashcardSetController.
16+
*
17+
* @param interactor the use case interactor for creating flashcard sets.
18+
*/
19+
public FlashcardSetController(FlashcardSetInputBoundary interactor) {
20+
this.interactor = interactor;
1121
}
1222

23+
/**
24+
* Creates a new flashcard set and stores it into the database.
25+
*
26+
* @param title the title of the flashcard set.
27+
* @param description the description of the flashcard set.
28+
* @param isPrivate the privacy of the flashcard set.
29+
* @param username the owner's username of the flashcard set.
30+
* @return the response model containing the newly created flashcard set data.
31+
*/
1332
FlashcardSetResponseModel create(String title, String description, boolean isPrivate, String username) {
1433
FlashcardSetRequestModel requestModel = new FlashcardSetRequestModel(title, description,
1534
isPrivate, username);
1635

17-
return userInput.create(requestModel);
36+
return interactor.create(requestModel);
1837
}
1938
}

src/main/java/create_flashcard_set_use_case/FlashcardSetCreationFailed.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package create_flashcard_set_use_case;
22

3+
/**
4+
* An exception class for when flashcard set creation fails.
5+
*
6+
* @author Edward Ishii
7+
*/
38
public class FlashcardSetCreationFailed extends RuntimeException {
9+
10+
/**
11+
* Throws a FlashcardSetCreationFailed error.
12+
*
13+
* @param error message of the error.
14+
*/
415
public FlashcardSetCreationFailed(String error) {
516
super(error);
617
}

src/main/java/create_flashcard_set_use_case/FlashcardSetInputBoundary.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
// Use case (Red) layer
44

5+
/**
6+
* The input boundary interface for creating flashcard sets.
7+
*
8+
* @author Edward Ishii
9+
*/
10+
511
public interface FlashcardSetInputBoundary {
12+
13+
/**
14+
* Create a new flashcard set and store it into the database.
15+
*
16+
* @param requestModel the request model required for flashcard set creation.
17+
* @return the response model containing the newly created flashcard set data.
18+
*/
619
FlashcardSetResponseModel create(FlashcardSetRequestModel requestModel) throws FlashcardSetCreationFailed;
720
}

src/main/java/create_flashcard_set_use_case/FlashcardSetInteractor.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import data_access.DBGateway;
44
import data_access.IFlashcardSetDataAccess;
5+
import data_access.entity_request_models.FlashcardSetDsRequestModel;
56
import entities.FlashcardSet;
67
import entities.FlashcardSetFactory;
7-
import data_access.entity_request_models.FlashcardSetDsRequestModel;
88

99
import java.util.ArrayList;
1010
import java.util.Objects;
@@ -22,23 +22,36 @@
2222
* - check that the flashcard set contains a title, description, and owner's username (if not, alert user)
2323
* - create and store newly created flashcard set
2424
* - notify successful creation of flashcard set to user
25+
*
26+
* @author Edward Ishii
2527
*/
26-
2728
public class FlashcardSetInteractor implements FlashcardSetInputBoundary {
2829
DBGateway dbGateway;
2930
IFlashcardSetDataAccess flashcardSetDataAccess; // for testing
3031
FlashcardSetOutputBoundary flashcardSetOutputBoundary;
3132
FlashcardSetFactory flashcardSetFactory;
3233

33-
34+
/**
35+
* Constructs the use case interactor.
36+
*
37+
* @param dbGateway the database to store the flashcard set in.
38+
* @param flashcardSetOutputBoundary the output boundary for preparing success/fail view of saving flashcard sets.
39+
* @param flashcardSetFactory the factory that creates flashcard sets.
40+
*/
3441
public FlashcardSetInteractor(DBGateway dbGateway, FlashcardSetOutputBoundary flashcardSetOutputBoundary,
3542
FlashcardSetFactory flashcardSetFactory) {
3643
this.dbGateway = dbGateway;
3744
this.flashcardSetOutputBoundary = flashcardSetOutputBoundary;
3845
this.flashcardSetFactory = flashcardSetFactory;
3946
}
4047

41-
// Alternative construction for testing purposes
48+
/**
49+
* Alternative constructor for testing purposes.
50+
*
51+
* @param flashcardSetDataAccess the flashcard set database.
52+
* @param flashcardSetOutputBoundary the output boundary for preparing success/fail view.
53+
* @param flashcardSetFactory the factory creating flashcard sets.
54+
*/
4255
public FlashcardSetInteractor(IFlashcardSetDataAccess flashcardSetDataAccess,
4356
FlashcardSetOutputBoundary flashcardSetOutputBoundary,
4457
FlashcardSetFactory flashcardSetFactory) {
@@ -47,6 +60,13 @@ public FlashcardSetInteractor(IFlashcardSetDataAccess flashcardSetDataAccess,
4760
this.flashcardSetFactory = flashcardSetFactory;
4861
}
4962

63+
/**
64+
* Creates a flashcard set and stores it into the database.
65+
*
66+
* @param inputData the request model containing data required for creating flashcard sets.
67+
* @return the response model containing the newly created flashcard set data.
68+
* @throws FlashcardSetCreationFailed the error thrown if flashcard set creation fails.
69+
*/
5070
@Override
5171
public FlashcardSetResponseModel create(FlashcardSetRequestModel inputData) throws FlashcardSetCreationFailed {
5272

@@ -70,21 +90,24 @@ public FlashcardSetResponseModel create(FlashcardSetRequestModel inputData) thro
7090
inputData.isPrivate(), tempFlashcardSetId, inputData.getUsername());
7191

7292
// store the flashcard set into database
73-
ArrayList<Integer> flashcardIds = new ArrayList<>(); // set starts with empty list of flashcard ids for database
93+
ArrayList<Integer> flashcardIds = new ArrayList<>(); // set starts with empty list of flashcard ids
7494
FlashcardSetDsRequestModel dsRequestModel = new FlashcardSetDsRequestModel(fs.getTitle(), fs.getDescription(),
7595
fs.getIsPrivate(), tempFlashcardSetId, fs.getOwnerUsername(), flashcardIds);
7696

7797
try {
78-
dbGateway.saveFlashcardSet(dsRequestModel);
79-
FlashcardSetResponseModel responseModel = new FlashcardSetResponseModel(fs);
98+
int savedFlashcardSetId = dbGateway.saveFlashcardSet(dsRequestModel);
99+
100+
// create the saved flashcard set with its proper id
101+
FlashcardSet savedFs = factory.create(inputData.getTitle(), inputData.getDescription(),
102+
inputData.isPrivate(), savedFlashcardSetId, inputData.getUsername());
103+
104+
FlashcardSetResponseModel responseModel = new FlashcardSetResponseModel(savedFs);
105+
80106
return flashcardSetOutputBoundary.prepareSuccessView(responseModel);
81-
} catch (Exception e) {
107+
} catch (NullPointerException e) {
82108
return null;
83109
}
84-
// dbGateway.saveFlashcardSet(dsRequestModel);
85-
// FlashcardSetResponseModel responseModel = new FlashcardSetResponseModel(fs);
86110

87-
// return flashcardSetOutputBoundary.prepareSuccessView(responseModel);
88111
}
89112

90113

src/main/java/create_flashcard_set_use_case/FlashcardSetOutputBoundary.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,27 @@
22

33
// Use case (Red) layer
44

5+
/**
6+
* The output boundary interface that updates the view when creating a flashcard set succeeds or fails.
7+
*
8+
* @author Edward Ishii
9+
*/
10+
511
public interface FlashcardSetOutputBoundary {
12+
/**
13+
* Prepares the success view when a flashcard set is created and saved.
14+
*
15+
* @param fs the flashcard set that has been created.
16+
* @return the response model containing the saved flashcard set data.
17+
*/
618
FlashcardSetResponseModel prepareSuccessView(FlashcardSetResponseModel fs);
719

20+
/**
21+
* Prepares the fail view when a flashcard set cannot be created or saved.
22+
*
23+
* @param error the failure message.
24+
* @return the response model containing the failure message.
25+
* @throws FlashcardSetCreationFailed the error thrown when flashcard set creation fails.
26+
*/
827
FlashcardSetResponseModel prepareFailView(String error) throws FlashcardSetCreationFailed;
928
}

src/main/java/create_flashcard_set_use_case/FlashcardSetPresenter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@
22

33
// Interface adapters (Green) layer
44

5+
/**
6+
* The presenter that updates the view when creating a flashcard set succeeds or fails.
7+
*
8+
* @author Edward Ishii
9+
*/
510
public class FlashcardSetPresenter implements FlashcardSetOutputBoundary {
11+
12+
/**
13+
* Prepares the success view when a flashcard set is created and saved.
14+
*
15+
* @param fs the flashcard set that has been created.
16+
* @return the response model containing the saved flashcard set data.
17+
*/
618
@Override
719
public FlashcardSetResponseModel prepareSuccessView(FlashcardSetResponseModel fs) {
820
return fs;
921
}
1022

23+
/**
24+
* Prepares the fail view when a flashcard set cannot be created or saved.
25+
*
26+
* @param error the failure message.
27+
* @return the response model containing the failure message.
28+
*/
1129
@Override
1230
public FlashcardSetResponseModel prepareFailView(String error) {
1331
throw new FlashcardSetCreationFailed(error);

0 commit comments

Comments
 (0)