Skip to content

Commit

Permalink
Merge pull request #231 from SebasFok/SebasFok/feat/refactorStorage
Browse files Browse the repository at this point in the history
Refactor storage
  • Loading branch information
SebasFok authored Nov 13, 2023
2 parents e9c8993 + 3380088 commit d81195a
Show file tree
Hide file tree
Showing 14 changed files with 624 additions and 570 deletions.
37 changes: 0 additions & 37 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,43 +236,6 @@ Command: `left`
Response:
`CS2030S CS2040S CS2100 CS2101 CS2106 CS2109S CS3230`

## Input Major Feature

The input major feature is facilitated by `Student`. It tries to store the major specified in userInput txt
file such that it can be used across sessions. It will print different responses based on whether the storing of the
Major was successful. Additionally, it implements the following operation:

- `Student#setMajor(Major major)` – Saves the selected major in its memory.

This operation is exposed in the `Student` interface as `Student#updateMajor(String userInput)`.

### Usage Examples

Here are a few examples of how the Input Major Feature behaves:

#### Example 1:
If "CS" is a valid major: `Student#updateMajor("major CS")` calls `Student#setMajor("CS")`, which sets the Major in the
student object as `CS` and returns a string `newMajor`

Command: `major CS`

Response: `Major CS selected!`


#### Example 2:
If "abc" is an invalid major: `Student#updateMajor("major abc")` calls `Student#setMajor("abc")`, which generates an
IllegalArgumentException, which is caught and returns a string `invalidMajor`

Command: `major abc`

Response: `Please select a major from this list: [list of currently available Majors]`

#### Example 3:
If no major was specified: `Student#updateMajor("major")` returns a string `currentMajor`

Command: `major`

Response: `Current major is [current major in student object].`

## Add Module Feature

Expand Down
Binary file modified docs/diagrams/updatedAddModule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 11 additions & 11 deletions src/main/java/seedu/duke/controllers/MainController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package seedu.duke.controllers;

import seedu.duke.models.schema.Storage;
import seedu.duke.storage.StorageManager;
import seedu.duke.models.schema.Student;
import seedu.duke.models.schema.CommandManager;
import seedu.duke.models.schema.UserCommand;
Expand All @@ -16,7 +16,7 @@

import static seedu.duke.controllers.ModuleServiceController.validateMajorInput;

import static seedu.duke.models.schema.Storage.saveTimetable;
import static seedu.duke.storage.StorageManager.saveTimetable;
import static seedu.duke.utils.Utility.detectInternet;
import static seedu.duke.utils.Utility.saveStudentData;
import static seedu.duke.views.Ui.displayWelcome;
Expand All @@ -27,14 +27,14 @@
import static seedu.duke.views.Ui.showLoadingAnimation;
import static seedu.duke.views.Ui.stopLoadingAnimation;

import static seedu.duke.models.schema.Storage.saveSchedule;
import static seedu.duke.storage.StorageManager.saveSchedule;


public class MainController {
private final Parser parser;
private final Student student;
private final CommandManager commandManager;
private Storage storage;
private StorageManager storageManager;

private final Ui ui;

Expand Down Expand Up @@ -62,7 +62,7 @@ public void start() throws IOException {
initialiseUser();
displayReady();
handleUserInputTillExitCommand();
saveStudentData(storage,student);
saveStudentData(storageManager,student);
displayGoodbye();
}
//@@author SebasFok
Expand All @@ -75,23 +75,23 @@ public void start() throws IOException {
*/
public void initialiseUser() throws IOException {

storage = new Storage();
storageManager = new StorageManager();
try {
System.out.println("Attempting to retrieve data from save file... Sorry this takes a while!");
showLoadingAnimation();
// Load name, major and year from studentDetails.txt file
ArrayList<String> studentDetails = storage.loadStudentDetails();
ArrayList<String> studentDetails = storageManager.loadStudentDetails();

// Set name, major and year from loaded data, throws exception if file is corrupted.
setStudentDetails(studentDetails);

// Load and set schedule from schedule.txt file
student.setSchedule(storage.loadSchedule());
student.setSchedule(storageManager.loadSchedule());

// Load timetable from timetable.txt file
try {
student.updateTimetable();
storage.addEventsToStudentTimetable(storage.loadTimetable(student), student);
storageManager.addEventsToStudentTimetable(storageManager.loadTimetable(student), student);

} catch (TimetableUnavailableException e) {
// no modules in current sem, do nothing
Expand Down Expand Up @@ -135,7 +135,7 @@ public void initialiseUser() throws IOException {
}

public void resetStorageData() throws IOException {
storage.createUserStorageFile();
storageManager.createUserStorageFile();

String userInput;

Expand All @@ -158,7 +158,7 @@ public void resetStorageData() throws IOException {
userInput = ui.getUserCommand("Please enter your current academic year: ").trim();
} while (!Parser.isValidAcademicYear(userInput.toUpperCase()));
student.setYear(userInput.toUpperCase());
storage.saveStudentDetails(student);
storageManager.saveStudentDetails(student);

//get blank schedule.txt
student.setSchedule(new Schedule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import static seedu.duke.controllers.ModuleServiceController.isConfirmedToClearSchedule;
import static seedu.duke.models.logic.Api.isValidModule;
import static seedu.duke.models.logic.Prerequisite.getModulePrereqBasedOnCourse;
import static seedu.duke.models.schema.Storage.saveSchedule;
import static seedu.duke.models.schema.Storage.saveTimetable;
import static seedu.duke.storage.StorageManager.saveSchedule;
import static seedu.duke.storage.StorageManager.saveTimetable;
import static seedu.duke.utils.errors.HttpError.displaySocketError;
import static seedu.duke.views.Ui.displayMessage;
import static seedu.duke.views.CommandLineView.displaySuccessfulAddMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import java.util.ArrayList;
import java.util.Scanner;

import static seedu.duke.models.schema.Storage.saveSchedule;
import static seedu.duke.models.schema.Storage.saveTimetable;
import static seedu.duke.storage.StorageManager.saveSchedule;
import static seedu.duke.storage.StorageManager.saveTimetable;
import static seedu.duke.utils.TimetableParser.isExitModify;
import static seedu.duke.views.MajorRequirementsView.printRequiredModules;
import static seedu.duke.views.SemesterPlannerView.displaySchedule;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/models/logic/Prerequisite.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;
import java.util.Objects;

import static seedu.duke.models.schema.Storage.getRequirements;
import static seedu.duke.storage.StorageManager.getRequirements;

public class Prerequisite {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/models/schema/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static seedu.duke.models.logic.Prerequisite.getModulePrereqBasedOnCourse;
import static seedu.duke.models.logic.Api.getModuleFulfilledRequirements;
import static seedu.duke.models.logic.Prerequisite.satisfiesAllPrereq;
import static seedu.duke.models.schema.Storage.getRequirements;
import static seedu.duke.storage.StorageManager.getRequirements;
import static seedu.duke.views.SemesterPlannerView.printSemesterPlanner;

/**
Expand Down
Loading

0 comments on commit d81195a

Please sign in to comment.