Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S1#37 from junhyeong0411/master
Browse files Browse the repository at this point in the history
Added Event Storage
  • Loading branch information
junhyeong0411 authored Oct 19, 2023
2 parents f62ccac + 18e8f65 commit 913c42c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
2 changes: 2 additions & 0 deletions data/events/event.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
submit v1.0 | 2023-10-29T23:59:59 | 2023-10-30T23:59:59
eat dinner | 2023-12-20T19:00 | 2023-12-20T20:00
8 changes: 8 additions & 0 deletions data/flashcards/flashcard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
d | a | - | - | -
dfdf | dfdf | - | - | -
dfdf | asdfdf | - | - | -
ddf | dfdf | - | - | -
hello | bye | - | - | -
hello | bye | - | - | -
end program | hello | - | - | -
hello | world | - | - | -
1 change: 1 addition & 0 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private void run() {

if (fc.isResponsible(input)) {
fc.processInput(input);

} else if (cm.isResponsible(input)) {
cm.processInput(input);
} else {
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/seedu/duke/calendar/CalendarManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import seedu.duke.calendar.command.EventCommand;
import seedu.duke.calendar.command.UnknownCommand;
import seedu.duke.calendar.Event;
import seedu.duke.flashcard.FlashcardStorage;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

Expand All @@ -16,12 +18,31 @@ public class CalendarManager {
CalendarCommandParser calendarCommandParser;
Scanner scanner;

private EventStorage storage;

public CalendarManager(ArrayList<Event> events) {
eventList = new EventList(events);

EventDirectory eventdirectory = new EventDirectory();
eventdirectory.listEventFiles();

storage = new EventStorage("./data/events/event.txt");

try{
eventList = storage.loadEvents();
} catch (FileNotFoundException e){
System.out.println("Making new file for Events");
eventList = new EventList(events);
}

calendar = new Calendar();
calendarUi = new CalendarUi(eventList);
calendarCommandParser = new CalendarCommandParser();
scanner = new Scanner(System.in);

}

public EventStorage getStorage(){
return this.storage;
}

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

public void processInput(String input) {
startCalendar(input);

storage.saveEvents(eventList.getEvent());
}

public void startCalendar(String input) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/calendar/EventDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public EventDirectory(){
file = new File(path);
if(!file.exists()){
if(file.mkdir()){
System.out.println(" Created data directory");
System.out.println(" Created events directory");
} else{
System.out.println(" Failed to create directory");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/flashcard/FlashcardComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public FlashcardComponent() {
try {
flashcardList = storage.loadFlashcards();
} catch (FileNotFoundException e){
System.out.println("Making New file");
System.out.println("Making New file for Flashcards");
flashcardList = new FlashcardList(new ArrayList<>());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/flashcard/FlashcardDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public FlashcardDirectory(){
file = new File(path);
if(!file.exists()){
if(file.mkdir()){
System.out.println(" Created data directory");
System.out.println(" Created flashcards directory");
} else{
System.out.println(" Failed to create directory");
}
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/seedu/duke/DukeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public void sampleTest() {

@Test
public void testFlashcardComponent_isResponsible_notResponsible() {
FlashcardComponent flashcardComponent = new FlashcardComponent(
new ArrayList<>());
FlashcardComponent flashcardComponent = new FlashcardComponent();

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

@Test
public void testFlashcardComponent_isResponsible_responsible() {
FlashcardComponent flashcardComponent = new FlashcardComponent(
new ArrayList<>());
FlashcardComponent flashcardComponent = new FlashcardComponent();

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

@Test
public void testFlashcardStorage_isAvailable(){
FlashcardComponent flashcardComponent = new FlashcardComponent(
new ArrayList<>());
FlashcardComponent flashcardComponent = new FlashcardComponent();
FlashcardStorage storage = flashcardComponent.getStorage();
assertTrue(storage.isStorageAvailable());
}
Expand Down

0 comments on commit 913c42c

Please sign in to comment.