2
2
3
3
// Use case (Red) layer
4
4
5
+ import dataAccess .DBGateway ;
5
6
import dataAccess .IFlashcardDataAccess ;
6
7
import dataAccess .IFlashcardSetDataAccess ;
7
8
19
20
20
21
public class DelFlashcardSetInteractor implements DelFlashcardSetInputBoundary {
21
22
22
-
23
-
24
- IFlashcardSetDataAccess flashcardSetDataAccess ;
25
- IFlashcardDataAccess flashcardDataAccess ; // for deleting flashcards associated with the flashcard set
23
+ DBGateway dbGateway ;
24
+ IFlashcardSetDataAccess flashcardSetDataAccess ; // for testing
25
+ IFlashcardDataAccess flashcardDataAccess ; // for testing
26
26
DelFlashcardSetOutputBoundary outputBoundary ;
27
27
28
+ public DelFlashcardSetInteractor (DBGateway dbGateway , DelFlashcardSetOutputBoundary outputBoundary ) {
29
+ this .dbGateway = dbGateway ;
30
+ this .outputBoundary = outputBoundary ;
31
+ }
32
+
33
+ // Alternative constructor for testing purposes
28
34
public DelFlashcardSetInteractor (IFlashcardSetDataAccess flashcardSetDataAccess ,
29
35
IFlashcardDataAccess flashcardDataAccess ,
30
36
DelFlashcardSetOutputBoundary outputBoundary ) {
@@ -36,16 +42,17 @@ public DelFlashcardSetInteractor(IFlashcardSetDataAccess flashcardSetDataAccess,
36
42
@ Override
37
43
public DelFlashcardSetResponseModel delete (DelFlashcardSetRequestModel requestModel ) {
38
44
39
- if (flashcardSetDataAccess .getFlashcardSet (requestModel .getFlashcardSetId ()) == null ) {
45
+ if (dbGateway .getFlashcardSet (requestModel .getFlashcardSetId ()) == null ) {
40
46
return outputBoundary .prepareFailView ("Flashcard set #"
41
47
+ requestModel .getFlashcardSetId () + " doesn't exist." );
42
48
} else {
43
49
// First delete all the flashcards associated with this flashcard set in Flashcards.csv
44
- for (int id : flashcardSetDataAccess .getFlashcardSet (requestModel .getFlashcardSetId ()).getFlashcardIds ()) {
45
- flashcardDataAccess .deleteFlashcard (id );
50
+ for (int id : dbGateway . getFlashcardSetGateway () .getFlashcardSet (requestModel .getFlashcardSetId ()).getFlashcardIds ()) {
51
+ dbGateway .deleteFlashcard (requestModel . getFlashcardSetId (), id );
46
52
}
47
53
// Then delete the flashcard set in FlashcardSets.csv
48
- flashcardSetDataAccess .deleteFlashcardSet (requestModel .getFlashcardSetId ());
54
+ dbGateway .deleteFlashcardSet (dbGateway .getFlashcardSet (requestModel .getFlashcardSetId ()).getOwnerUsername (),
55
+ requestModel .getFlashcardSetId ());
49
56
50
57
return outputBoundary .prepareSuccessView ("Flashcard set #" + requestModel .getFlashcardSetId ()
51
58
+ " has been deleted." );
0 commit comments