Skip to content

Commit 80a5e02

Browse files
committed
Merge remote-tracking branch 'origin/feature-4-editing-flashcard-set' into feature-5-flashcard-creator-and-remover
2 parents ce553fe + f4826b9 commit 80a5e02

File tree

57 files changed

+1848
-62
lines changed

Some content is hidden

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

57 files changed

+1848
-62
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.

src/data/FlashcardSets.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
title, description, privacy, id, owner, flashcardsIds
22
test set,for testing study use case,true,0,testUser,0,1,2,3
33
empty test set,for testing study use case with empty set,true,1,testUser,
4+
csc207,flashcards for csc207,true,2,jempio,1,4,5,6,7
5+
csc207,flashcards for csc207,true,3,jempio,1,4,5,6,7
6+
csc207,flashcards for csc207,true,4,jempio,1,4,5,6,7
7+
csc207,flashcards for csc207,true,5,jempio,1,4,5,6,7
8+
csc207,flashcards for csc207,true,6,jempio,1,4,5,6,7
9+
csc207,flashcards for csc207,false,7,jempio,1,4,5,6,7
10+
csc207,flashcards for csc207,false,8,jempio,1,4,5,6,7

src/data/Flashcards.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
term, definition, creationDate, flashcardId, belongsToId
1+
term,definition,creationDate,flashcardId,belongsToId
22
test card 1,the first test card,2022-11-13T15:32:26.666982800,0,0
33
test card 2,the second test card,2022-11-13T15:32:27.666982800,1,0
44
test card 3,the third test card,2022-11-13T15:32:28.666982800,2,0

src/data/Users.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
username,password,isAdmin,flashcardSetsIds
2-
testUser,456r2t17yuihjn@,false,0,1
2+
testUser,456r2t17yuihjn@,false,0,1
3+
jempio,ilovejempio,false,3,4,5,6,7,8
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Editor.Flashcard;
2+
3+
public interface FlashcardEditorInputBoundary {
4+
FlashcardEditorResponseModel edit(FlashcardEditorRequestModel requestModel);
5+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package Editor.Flashcard;
2+
3+
import dataAccess.DBGateway;
4+
import dataAccess.IFlashcardDataAccess;
5+
import entityRequestModels.FlashcardDsRequestModel;
6+
7+
import java.time.LocalDateTime;
8+
9+
public class FlashcardEditorInteractor implements FlashcardEditorInputBoundary {
10+
11+
final DBGateway dbGateway;
12+
final FlashcardEditorOutputBoundary fcEditorOB;
13+
final IFlashcardDataAccess fcDBGateway;
14+
15+
16+
public FlashcardEditorInteractor(DBGateway dbGateway, FlashcardEditorOutputBoundary fcEditorOB){
17+
this.dbGateway = dbGateway;
18+
this.fcEditorOB = fcEditorOB;
19+
this.fcDBGateway = dbGateway.getFlashcardGateway();
20+
}
21+
@Override
22+
public FlashcardEditorResponseModel edit(FlashcardEditorRequestModel requestModel) {
23+
String termEdit = requestModel.getTermEdit();
24+
String definitionEdit = requestModel.getDefinitionEdit();
25+
int flashcardId = requestModel.getFlashcardId();
26+
27+
if (termEdit.equals("")){
28+
return fcEditorOB.prepareFailView("Error: Term input cannot be empty.");
29+
}
30+
else{
31+
FlashcardDsRequestModel oldFlashcard = fcDBGateway.getFlashcard(flashcardId);
32+
LocalDateTime creationDate = oldFlashcard.getCreationDate();
33+
int belongsToId = oldFlashcard.getBelongsToId();
34+
FlashcardDsRequestModel newFlashcard = new FlashcardDsRequestModel(termEdit, definitionEdit, creationDate, flashcardId, belongsToId);
35+
36+
fcDBGateway.editFlashcard(newFlashcard);
37+
38+
FlashcardEditorResponseModel responseModel = new FlashcardEditorResponseModel(flashcardId, termEdit, definitionEdit);
39+
return fcEditorOB.prepareSuccessView(responseModel);
40+
}
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package Editor.Flashcard;
2+
3+
import Editor.Flashcard.screens.FlashcardEditorController;
4+
import Editor.Flashcard.screens.FlashcardEditorPresenter;
5+
import Editor.Flashcard.screens.FlashcardEditorScreen;
6+
import dataAccess.*;
7+
import entityRequestModels.FlashcardDsRequestModel;
8+
9+
import javax.swing.*;
10+
import java.io.IOException;
11+
12+
public class FlashcardEditorMain extends JFrame{
13+
14+
public FlashcardEditorMain(DBGateway dbGateway, FlashcardDsRequestModel flashcard){
15+
FlashcardEditorOutputBoundary presenter = new FlashcardEditorPresenter();
16+
17+
FlashcardEditorInputBoundary interactor = new FlashcardEditorInteractor(dbGateway, presenter);
18+
FlashcardEditorController controller = new FlashcardEditorController(interactor);
19+
20+
21+
this.setTitle("Edit Flashcard \"" + flashcard.getTerm() + "\"");
22+
FlashcardEditorScreen editScreen = new FlashcardEditorScreen(controller, flashcard, this);
23+
this.add(editScreen);
24+
this.setSize(500, 200);
25+
this.setVisible(true);
26+
}
27+
28+
public static void main(String[] args) {
29+
IFlashcardDataAccess fcDataAccess;
30+
try{
31+
fcDataAccess = new FlashcardDataAccess("src/data/Flashcards.csv");
32+
}
33+
catch(IOException e){
34+
throw new RuntimeException("no file found");
35+
}
36+
DBGateway dbGateway = new DBGateway(fcDataAccess, null, null);
37+
FlashcardDsRequestModel fc = new FlashcardDsRequestModel("Term", "the first test card", null, 0, 0);
38+
new FlashcardEditorMain(dbGateway, fc);
39+
}
40+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package Editor.Flashcard;
2+
3+
public interface FlashcardEditorOutputBoundary {
4+
FlashcardEditorResponseModel prepareSuccessView(FlashcardEditorResponseModel flashcard);
5+
FlashcardEditorResponseModel prepareFailView(String error);
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Editor.Flashcard;
2+
3+
4+
public class FlashcardEditorRequestModel {
5+
private final int flashcardId;
6+
private final String termEdit;
7+
private final String definitionEdit;
8+
9+
public FlashcardEditorRequestModel(int flashcardId, String term, String definition){
10+
this.flashcardId = flashcardId;
11+
termEdit = term;
12+
definitionEdit = definition;
13+
}
14+
15+
public int getFlashcardId() {
16+
return flashcardId;
17+
}
18+
19+
public String getDefinitionEdit() {
20+
return definitionEdit;
21+
}
22+
23+
public String getTermEdit() {
24+
return termEdit;
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Editor.Flashcard;
2+
3+
public class FlashcardEditorResponseModel {
4+
private final int flashcardId;
5+
private final String termEdit;
6+
private final String definitionEdit;
7+
8+
public FlashcardEditorResponseModel(int flashcardId, String term, String definition){
9+
this.flashcardId = flashcardId;
10+
termEdit = term;
11+
definitionEdit = definition;
12+
}
13+
14+
public int getFlashcardId() {
15+
return flashcardId;
16+
}
17+
18+
public String getDefinitionEdit() {
19+
return definitionEdit;
20+
}
21+
22+
public String getTermEdit() {
23+
return termEdit;
24+
}
25+
}

0 commit comments

Comments
 (0)