Skip to content

Commit 7761ce2

Browse files
committed
Added Javadocs for all classes and methods pertaining to delete a flashcard set use case.
1 parent 42f67de commit 7761ce2

9 files changed

+163
-9
lines changed

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetController.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@
22

33
// Interface adapters (Green) layer
44

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

7-
DelFlashcardSetInputBoundary userInput;
12+
DelFlashcardSetInputBoundary interactor;
813

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

23+
/**
24+
* Deletes a flashcard set (and all the flashcards contained within it) from the database.
25+
*
26+
* @param flashcardSetId the id of the flashcard set to be deleted.
27+
* @return the response model containing the deletion message.
28+
*/
1329
DelFlashcardSetResponseModel delete(int flashcardSetId) {
1430
DelFlashcardSetRequestModel requestModel = new DelFlashcardSetRequestModel(flashcardSetId);
1531

16-
return userInput.delete(requestModel);
32+
return interactor.delete(requestModel);
1733
}
1834
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package delete_flashcard_set_use_case;
22

3+
/**
4+
* The input boundary interface for deleting flashcard sets.
5+
*
6+
* @author Edward Ishii
7+
*/
38
public interface DelFlashcardSetInputBoundary {
9+
10+
/**
11+
* Delete the flashcard set (and all the flashcards contained within it) from the database.
12+
*
13+
* @param requestModel the request model required for flashcard set deletion (i.e., the id).
14+
* @return the response model containing the deletion message.
15+
*/
416
DelFlashcardSetResponseModel delete(DelFlashcardSetRequestModel requestModel);
517
}

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetInteractor.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package delete_flashcard_set_use_case;
22

3-
// Use case (Red) layer
4-
53
import data_access.DBGateway;
64

5+
// Use case (Red) layer
6+
77
/**
88
* [Feature: Deleting a Flashcard Set]
99
* UI:
@@ -14,20 +14,33 @@
1414
* - check that the flashcard set exists in the database (if not alert the user)
1515
* - if it exists, ask for confirmation to delete from the user
1616
* - notify successful deletion of flashcard set to the user
17+
*
18+
* @author Edward Ishii
1719
*/
18-
1920
public class DelFlashcardSetInteractor implements DelFlashcardSetInputBoundary {
2021

2122
DBGateway dbGateway;
2223

2324
DelFlashcardSetOutputBoundary outputBoundary;
2425

26+
/**
27+
* Constructs the use case interactor.
28+
*
29+
* @param dbGateway the database to modify so that the flashcard set is deleted.
30+
* @param outputBoundary the output boundary that prepares the success/fail view of deleting flashcard sets.
31+
*/
2532
public DelFlashcardSetInteractor(DBGateway dbGateway, DelFlashcardSetOutputBoundary outputBoundary) {
2633
this.dbGateway = dbGateway;
2734
this.outputBoundary = outputBoundary;
2835
}
2936

30-
// Alternative constructor for testing purposes
37+
// /**
38+
// * Alternative constructor for testing purposes.
39+
// *
40+
// * @param flashcardSetDataAccess the flashcard set database.
41+
// * @param flashcardDataAccess the flashcard database.
42+
// * @param outputBoundary the output boundary for preparing success/fail view.
43+
// */
3144
// public DelFlashcardSetInteractor(IFlashcardSetDataAccess flashcardSetDataAccess,
3245
// IFlashcardDataAccess flashcardDataAccess,
3346
// DelFlashcardSetOutputBoundary outputBoundary) {
@@ -36,6 +49,12 @@ public DelFlashcardSetInteractor(DBGateway dbGateway, DelFlashcardSetOutputBound
3649
// this.outputBoundary = outputBoundary;
3750
// }
3851

52+
/**
53+
* Delete the flashcard set (and all the flashcards contained within it) from the database.
54+
*
55+
* @param requestModel the request model required for flashcard set deletion (i.e., the id).
56+
* @return the response model that contains the deletion message.
57+
*/
3958
@Override
4059
public DelFlashcardSetResponseModel delete(DelFlashcardSetRequestModel requestModel) {
4160

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetOutputBoundary.java

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

33
// Use case (Red) layer
44

5+
/**
6+
* The output boundary interface that updates the view when deleting a flashcard set succeeds or fails.
7+
*
8+
* @author Edward Ishii
9+
*/
510
public interface DelFlashcardSetOutputBoundary {
611

12+
/**
13+
* Prepares the success view when flashcard set deletion succeeds.
14+
*
15+
* @param message the confirmation of deletion message.
16+
* @return the response model containing the deletion message.
17+
*/
718
DelFlashcardSetResponseModel prepareSuccessView(String message);
819

20+
/**
21+
* Prepares the failure view when flashcard set deletion fails.
22+
*
23+
* @param error the error message.
24+
* @return the response model containing the error message.
25+
* @throws FlashcardSetNotFound the error thrown when the flashcard set to be deleted is not found in the database.
26+
*/
927
DelFlashcardSetResponseModel prepareFailView(String error) throws FlashcardSetNotFound;
1028
}

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetPresenter.java

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

33
// Interface adapters (Green) layer
44

5+
/**
6+
* The presenter that updates the view when deleting a flashcard set succeeds or fails.
7+
*
8+
* @author Edward Ishii
9+
*/
510
public class DelFlashcardSetPresenter implements DelFlashcardSetOutputBoundary {
611

12+
/**
13+
* Prepares the success view when flashcard set deletion succeeds.
14+
*
15+
* @param message the confirmation of deletion message.
16+
* @return the response model containing the deletion message.
17+
*/
718
@Override
819
public DelFlashcardSetResponseModel prepareSuccessView(String message) {
920
return new DelFlashcardSetResponseModel(message);
1021
}
1122

23+
/**
24+
* Prepares the failure view when flashcard set deletion fails.
25+
*
26+
* @param error the error message.
27+
* @return the response model containing the error message.
28+
* @throws FlashcardSetNotFound the error thrown when the flashcard set to be deleted is not found in the database.
29+
*/
1230
@Override
1331
public DelFlashcardSetResponseModel prepareFailView(String error) {
1432
throw new FlashcardSetNotFound(error);

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetRequestModel.java

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

33
// Use case (Red) layer
44

5+
/**
6+
* The request model required for deleting a flashcard set.
7+
*
8+
* @author Edward Ishii
9+
*/
510
public class DelFlashcardSetRequestModel {
611

712
private int flashcardSetId;
813

14+
/**
15+
* Constructs the request model.
16+
*
17+
* @param flashcardSetId the id of the flashcard set to be deleted.
18+
*/
919
public DelFlashcardSetRequestModel(int flashcardSetId) {
1020
this.flashcardSetId = flashcardSetId;
1121
}
1222

23+
/**
24+
* Getter for the flashcard set id.
25+
*
26+
* @return the id of this flashcard set.
27+
*/
1328
public int getFlashcardSetId() {
1429
return flashcardSetId;
1530
}
1631

32+
/**
33+
* Setter for the flashcard set id.
34+
*
35+
* @param flashcardSetId the new id of this flashcard set.
36+
*/
1737
public void setFlashcardSetId(int flashcardSetId) {
1838
this.flashcardSetId = flashcardSetId;
1939
}

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetResponseModel.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,39 @@
22

33
// Use case (Red) layer
44

5+
6+
/**
7+
* The response model with the delete message when a flashcard set is deleted.
8+
*
9+
* @author Edward Ishii
10+
*/
511
public class DelFlashcardSetResponseModel {
612

713
private String message;
814

15+
/**
16+
* Constructs a DelFlashcardSetResponseModel.
17+
*
18+
* @param message the message to be displayed when a flashcard set is deleted.
19+
*/
920
public DelFlashcardSetResponseModel(String message) {
1021
this.message = message;
1122
}
1223

24+
/**
25+
* Getter for the delete message.
26+
*
27+
* @return the message displayed when a flashcard set is deleted.
28+
*/
1329
public String getMessage() {
14-
return message;
30+
return this.message;
1531
}
1632

33+
/**
34+
* Setter for the delete message.
35+
*
36+
* @param message the new delete message to be displayed.
37+
*/
1738
public void setMessage(String message) {
1839
this.message = message;
1940
}

src/main/java/delete_flashcard_set_use_case/FlashcardSetNotFound.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
package delete_flashcard_set_use_case;
22

3+
/**
4+
* An exception class for when flashcard set deletion fails, specifically, the id of flashcard set to be
5+
* deleted does not exist in the database.
6+
*
7+
* @author Edward Ishii
8+
*/
39
public class FlashcardSetNotFound extends RuntimeException {
410

11+
/**
12+
* Throws a FlashcardSetNotFound error.
13+
*
14+
* @param error message of the error.
15+
*/
516
public FlashcardSetNotFound(String error) {
617
super(error);
718
}

src/main/java/delete_flashcard_set_use_case/InMemoryFlashcard.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
import java.util.ArrayList;
77

8+
/**
9+
* A mock flashcard repository for testing purposes.
10+
*
11+
* @author Edward Ishii
12+
*/
813
public class InMemoryFlashcard implements IFlashcardDataAccess {
914

1015
// Mock database
@@ -15,6 +20,10 @@ private boolean checkIds(int id1, int id2) {
1520
return id1 == id2;
1621
}
1722

23+
/**
24+
* @param flashcardID the id of the flashcard.
25+
* @return the flashcard associated with the id.
26+
*/
1827
@Override
1928
public FlashcardDsRequestModel getFlashcard(Integer flashcardID) {
2029
for (FlashcardDsRequestModel fc : flashcards) {
@@ -25,18 +34,28 @@ public FlashcardDsRequestModel getFlashcard(Integer flashcardID) {
2534
return null;
2635
}
2736

37+
/**
38+
* @param flashcard the flashcard that is to be saved.
39+
* @return the id of the flashcard that was saved.
40+
*/
2841
@Override
2942
public int saveFlashcard(FlashcardDsRequestModel flashcard) {
3043
flashcards.add(flashcard);
3144
System.out.println("Flashcard [" + flashcard.getTerm() + "] has been saved.");
3245
return flashcard.getFlashcardId();
3346
}
3447

48+
/**
49+
* @param flashcard the flashcard that is to be edited.
50+
*/
3551
@Override
3652
public void editFlashcard(FlashcardDsRequestModel flashcard) {
3753

3854
}
3955

56+
/**
57+
* @param flashcardID the id of the flashcard.
58+
*/
4059
@Override
4160
public void deleteFlashcard(Integer flashcardID) {
4261
boolean deleted = false;

0 commit comments

Comments
 (0)