Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for duplicate lesson and consult #218

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,104 @@ Examples:
* `list` followed by `delete 2;3` deletes the 2nd and 3rd student in TAHub.
* `find n/Betsy` followed by `delete 1` deletes the 1st student in the results of the `find` command.

### Adding a consultation : `addconsult`

Adds a new consultation to TAHub.

**Format**: `addconsult d/DATE t/TIME`

* The date and time should not conflict with any existing consultation.
* Date format: `YYYY-MM-DD`
* Time format: `HH:MM`

**Examples**:
* `addconsult d/2024-10-20 t/14:00`
* `addconsult d/2024-11-05 t/09:00`

### Listing all consultations : `listconsults`

Displays a list of all consultations in TAHub.

**Format**: `listconsults`

**Example**:
* `listconsults`

### Adding students to a consultation : `addtoconsult`

Adds students to an existing consultation, specified by its index.

**Format**: `addtoconsult INDEX [n/NAME]... [i/INDEX]...`

* `INDEX` specifies the consultation to add students to.
* Student names (`n/NAME`) and/or student indices (`i/INDEX`) can be used to specify students.
* Students already in the consultation will not be added again, and an error message will be shown.

**Examples**:
* `addtoconsult 1 n/John Doe n/Harry Ng`
* `addtoconsult 2 i/3 i/5` (adds students at indices 3 and 5 in the student list to the 2nd consultation)

---

### Removing students from a consultation : `removefromconsult`

Removes specified students from a consultation, identified by its index.

**Format**: `removefromconsult INDEX n/NAME...`

* `INDEX` is the index of the consultation from which the students will be removed.
* Specify one or more students to remove by their names.

**Examples**:
* `removefromconsult 1 n/John Doe n/Harry Ng` (removes students named John Doe and Harry Ng from the 1st consultation)

---

### Deleting consultations : `deleteconsult`

Deletes one or more consultations from TAHub by their indices.

**Format**: `deleteconsult INDEX[;INDEX]...`

* `INDEX` specifies the consultation to delete. You can delete multiple consultations by separating indices with semicolons (`;`).

**Examples**:
* `deleteconsult 2`
* `deleteconsult 1;3;5` (deletes the 1st, 3rd, and 5th consultations)

### Exporting consultations : `exportconsult`

Exports all consultations currently displayed in TAHub to a CSV file.

**Format**: `exportconsult FILENAME [-f]`

* `FILENAME` specifies the name of the CSV file (without the extension).
* `-f` flag forces overwriting if a file with the same name already exists.

**Examples**:
* `exportconsult consultations`
* `exportconsult consultations_backup -f`

**Output**:
* The file will contain columns for Date, Time, and Students, with students separated by semicolons.

### Importing consultations : `importconsult`

Imports consultations from a specified CSV file into TAHub.

**Format**: `importconsult FILENAME`

* `FILENAME` specifies the file to import consultations from.
* The file should be in CSV format with columns for Date, Time, and Students.
* If any entries contain errors (e.g., student not found in TAHub), those entries are recorded in an error file.

**Examples**:
* `importconsult consultations.csv`
* `importconsult ~/documents/consultations.csv`

**File Format**:
* `Date, Time, Students`
* Each student name should be separated by a semicolon (`;`).

### Clearing all entries : `clear`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

// Check if the model already has a consultation with the same date and time
if (model.hasConsult(newConsult)) {
throw new CommandException("Duplicate consultation."

Check warning on line 60 in src/main/java/seedu/address/logic/commands/consultation/AddConsultCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/consultation/AddConsultCommand.java#L60

Added line #L60 was not covered by tests
marcusjhang marked this conversation as resolved.
Show resolved Hide resolved
+ " A consultation with this date and time already exists.");
}

// Add the consultation if it's unique
model.addConsult(newConsult);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(newConsult)),
COMMAND_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.lesson.Lesson;
import seedu.address.model.lesson.exceptions.DuplicateLessonException;

/**
* Adds a lesson to the address book.
Expand Down Expand Up @@ -54,9 +55,13 @@
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.addLesson(newLesson);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(newLesson)),
COMMAND_TYPE);

try {
model.addLesson(newLesson);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(newLesson)), COMMAND_TYPE);
} catch (DuplicateLessonException e) {
throw new CommandException("Duplicate lesson. A lesson with this date and time already exists.");

Check warning on line 63 in src/main/java/seedu/address/logic/commands/lesson/AddLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/lesson/AddLessonCommand.java#L62-L63

Added lines #L62 - L63 were not covered by tests
marcusjhang marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
Expand Down
Loading