Skip to content

Commit 913c42c

Browse files
Merge pull request nus-cs2113-AY2324S1#37 from junhyeong0411/master
Added Event Storage
2 parents f62ccac + 18e8f65 commit 913c42c

File tree

8 files changed

+41
-10
lines changed

8 files changed

+41
-10
lines changed

data/events/event.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
submit v1.0 | 2023-10-29T23:59:59 | 2023-10-30T23:59:59
2+
eat dinner | 2023-12-20T19:00 | 2023-12-20T20:00

data/flashcards/flashcard.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
d | a | - | - | -
2+
dfdf | dfdf | - | - | -
3+
dfdf | asdfdf | - | - | -
4+
ddf | dfdf | - | - | -
5+
hello | bye | - | - | -
6+
hello | bye | - | - | -
7+
end program | hello | - | - | -
8+
hello | world | - | - | -

src/main/java/seedu/duke/Duke.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private void run() {
2828

2929
if (fc.isResponsible(input)) {
3030
fc.processInput(input);
31+
3132
} else if (cm.isResponsible(input)) {
3233
cm.processInput(input);
3334
} else {

src/main/java/seedu/duke/calendar/CalendarManager.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import seedu.duke.calendar.command.EventCommand;
66
import seedu.duke.calendar.command.UnknownCommand;
77
import seedu.duke.calendar.Event;
8+
import seedu.duke.flashcard.FlashcardStorage;
89

10+
import java.io.FileNotFoundException;
911
import java.util.ArrayList;
1012
import java.util.Scanner;
1113

@@ -16,12 +18,31 @@ public class CalendarManager {
1618
CalendarCommandParser calendarCommandParser;
1719
Scanner scanner;
1820

21+
private EventStorage storage;
22+
1923
public CalendarManager(ArrayList<Event> events) {
20-
eventList = new EventList(events);
24+
25+
EventDirectory eventdirectory = new EventDirectory();
26+
eventdirectory.listEventFiles();
27+
28+
storage = new EventStorage("./data/events/event.txt");
29+
30+
try{
31+
eventList = storage.loadEvents();
32+
} catch (FileNotFoundException e){
33+
System.out.println("Making new file for Events");
34+
eventList = new EventList(events);
35+
}
36+
2137
calendar = new Calendar();
2238
calendarUi = new CalendarUi(eventList);
2339
calendarCommandParser = new CalendarCommandParser();
2440
scanner = new Scanner(System.in);
41+
42+
}
43+
44+
public EventStorage getStorage(){
45+
return this.storage;
2546
}
2647

2748
public boolean validCommand(String input) {
@@ -36,6 +57,8 @@ public boolean isResponsible(String input) {
3657

3758
public void processInput(String input) {
3859
startCalendar(input);
60+
61+
storage.saveEvents(eventList.getEvent());
3962
}
4063

4164
public void startCalendar(String input) {

src/main/java/seedu/duke/calendar/EventDirectory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public EventDirectory(){
1919
file = new File(path);
2020
if(!file.exists()){
2121
if(file.mkdir()){
22-
System.out.println(" Created data directory");
22+
System.out.println(" Created events directory");
2323
} else{
2424
System.out.println(" Failed to create directory");
2525
}

src/main/java/seedu/duke/flashcard/FlashcardComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public FlashcardComponent() {
2727
try {
2828
flashcardList = storage.loadFlashcards();
2929
} catch (FileNotFoundException e){
30-
System.out.println("Making New file");
30+
System.out.println("Making New file for Flashcards");
3131
flashcardList = new FlashcardList(new ArrayList<>());
3232
}
3333

src/main/java/seedu/duke/flashcard/FlashcardDirectory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public FlashcardDirectory(){
2020
file = new File(path);
2121
if(!file.exists()){
2222
if(file.mkdir()){
23-
System.out.println(" Created data directory");
23+
System.out.println(" Created flashcards directory");
2424
} else{
2525
System.out.println(" Failed to create directory");
2626
}

src/test/java/seedu/duke/DukeTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public void sampleTest() {
1717

1818
@Test
1919
public void testFlashcardComponent_isResponsible_notResponsible() {
20-
FlashcardComponent flashcardComponent = new FlashcardComponent(
21-
new ArrayList<>());
20+
FlashcardComponent flashcardComponent = new FlashcardComponent();
2221

2322
assertFalse(flashcardComponent.isResponsible("dfdfdfdfdf"));
2423
assertFalse(flashcardComponent.isResponsible("help me"));
@@ -27,8 +26,7 @@ public void testFlashcardComponent_isResponsible_notResponsible() {
2726

2827
@Test
2928
public void testFlashcardComponent_isResponsible_responsible() {
30-
FlashcardComponent flashcardComponent = new FlashcardComponent(
31-
new ArrayList<>());
29+
FlashcardComponent flashcardComponent = new FlashcardComponent();
3230

3331
assertTrue(flashcardComponent.isResponsible("create flashcard"));
3432
assertTrue(flashcardComponent.isResponsible("create flashcard "));
@@ -37,8 +35,7 @@ public void testFlashcardComponent_isResponsible_responsible() {
3735

3836
@Test
3937
public void testFlashcardStorage_isAvailable(){
40-
FlashcardComponent flashcardComponent = new FlashcardComponent(
41-
new ArrayList<>());
38+
FlashcardComponent flashcardComponent = new FlashcardComponent();
4239
FlashcardStorage storage = flashcardComponent.getStorage();
4340
assertTrue(storage.isStorageAvailable());
4441
}

0 commit comments

Comments
 (0)