Skip to content

Commit 6534ced

Browse files
Merge branch 'main' of https://github.com/CSC207-2022F-UofT/course-project-team-bbq into Anthony's_Branch
2 parents 6b375c0 + 838fcd6 commit 6534ced

19 files changed

+391
-34
lines changed

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);

src/main/java/create_flashcard_set_use_case/FlashcardSetRequestModel.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,100 @@
22

33
// Use case (Red) layer
44

5+
/**
6+
* The request model required for creating a flashcard set.
7+
*
8+
* @author Edward Ishii
9+
*/
510
public class FlashcardSetRequestModel {
611
private String title;
712
private String description;
813
private boolean isPrivate;
914
private String username;
1015

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+
*/
1124
public FlashcardSetRequestModel(String title, String description, boolean isPrivate, String username) {
1225
this.title = title;
1326
this.description = description;
1427
this.isPrivate = isPrivate;
1528
this.username = username;
1629
}
1730

31+
/**
32+
* Getter for the flashcard set title.
33+
*
34+
* @return the title of this flashcard set.
35+
*/
1836
public String getTitle() {
1937
return title;
2038
}
2139

40+
/**
41+
* Setter for the flashcard set title.
42+
*
43+
* @param title the new title for this flashcard set.
44+
*/
2245
public void setTitle(String title) {
2346
this.title = title;
2447
}
2548

49+
/**
50+
* Getter for the description of the flashcard set.
51+
*
52+
* @return the description of this flashcard set.
53+
*/
2654
public String getDescription() {
2755
return description;
2856
}
2957

58+
/**
59+
* Setter for the description of the flashcard set.
60+
*
61+
* @param description the new description for this flashcard set.
62+
*/
3063
public void setDescription(String description) {
3164
this.description = description;
3265
}
3366

67+
/**
68+
* Getter for the privacy of the flashcard set.
69+
*
70+
* @return the privacy of this flashcard set.
71+
*/
3472
public boolean isPrivate() {
3573
return isPrivate;
3674
}
3775

76+
/**
77+
* Setter for the privacy of the flashcard set.
78+
*
79+
* @param aPrivate the new privacy status for this flashcard set.
80+
*/
3881
public void setPrivate(boolean aPrivate) {
3982
isPrivate = aPrivate;
4083
}
4184

85+
/**
86+
* Getter for the owner's username of the flashcard set.
87+
*
88+
* @return the owner's username of this flashcard set.
89+
*/
4290
public String getUsername() {
4391
return username;
4492
}
4593

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+
*/
4699
public void setUsername(String username) {
47100
this.username = username;
48101
}
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
package create_flashcard_set_use_case;
22

3-
// Use case (Red) layer
4-
53
import entities.FlashcardSet;
64

5+
// Use case (Red) layer
6+
7+
/**
8+
* The response model containing data from the newly created flashcard set.
9+
*
10+
* @author Edward Ishii
11+
*/
712
public class FlashcardSetResponseModel {
813
private final FlashcardSet fs;
914

15+
/**
16+
* Constructs a FlashcardSetResponseModel.
17+
*
18+
* @param fs the flashcard set.
19+
*/
1020
public FlashcardSetResponseModel(FlashcardSet fs) {
1121
this.fs = fs;
1222
}
1323

24+
/**
25+
* Getter for the flashcard set.
26+
*
27+
* @return the flashcard set.
28+
*/
1429
public FlashcardSet getFs() {
1530
return fs;
1631
}
17-
1832
}

0 commit comments

Comments
 (0)