From a5dbd1c7d4141149c6557fbc2d167c2e210b8b68 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Sun, 7 Apr 2024 22:07:47 +0800 Subject: [PATCH 01/12] First commit to fix ped bugs. Currently working on null prefix execption --- build.gradle | 5 ++ .../seedu/address/commons/util/FileUtil.java | 2 +- .../logic/commands/AddProfCommand.java | 63 +++++++++++++++++++ .../logic/parser/BookCommandParser.java | 13 +++- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/AddProfCommand.java diff --git a/build.gradle b/build.gradle index d63c852e500..6a9b7c9831b 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ repositories { maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } } + checkstyle { toolVersion = '10.2' } @@ -73,6 +74,10 @@ shadowJar { archiveFileName = 'addressbook.jar' } +processResources { + duplicatesStrategy = 'exclude' +} + defaultTasks 'clean', 'test' run { diff --git a/src/main/java/seedu/address/commons/util/FileUtil.java b/src/main/java/seedu/address/commons/util/FileUtil.java index b1e2767cdd9..8cde4b94064 100644 --- a/src/main/java/seedu/address/commons/util/FileUtil.java +++ b/src/main/java/seedu/address/commons/util/FileUtil.java @@ -18,7 +18,7 @@ public static boolean isFileExists(Path file) { } /** - * Returns true if {@code path} can be converted into a {@code Path} via {@link Paths#get(String)}, + * Returns true if {@code path} can be converted into a {@code Path}, * otherwise returns false. * @param path A string representing the file path. Cannot be null. */ diff --git a/src/main/java/seedu/address/logic/commands/AddProfCommand.java b/src/main/java/seedu/address/logic/commands/AddProfCommand.java new file mode 100644 index 00000000000..0af1fe336c2 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/AddProfCommand.java @@ -0,0 +1,63 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.Person; + +/** + * Adds professors to the address book. Can add all professors or those matching a given name. + */ +public class AddProfCommand extends Command { + public static final String COMMAND_WORD = "prof"; + + public static final String MESSAGE_SUCCESS = "Professors Added!"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds professors to the address book.\n" + + "Parameters: -a (to add all professors) or " + + PREFIX_NAME + "NAME (to add professors by name)\n" + + "Example: " + COMMAND_WORD + " -a\n" + + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "Aaron"; + + private final boolean addAll; + private final NameContainsKeywordsPredicate profPredicate; + + /** + * Constructor for creating an {@code AddProfCommand} to add all professors. + * This constructor sets the command to add all professors without filtering by name. + */ + public AddProfCommand() { + this.addAll = true; + this.profPredicate = null; + } + + /** + * Constructor for creating an {@code AddProfCommand} with a specific name filter. + * This constructor sets the command to add professors filtered by the specified name predicate. + * + * @param profPredicate The {@code NameContainsKeywordsPredicate} used for filtering professors by name. + */ + public AddProfCommand(NameContainsKeywordsPredicate profPredicate) { + this.profPredicate = profPredicate; + this.addAll = false; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + if (addAll) { + model.updateFilteredProfList(PREDICATE_SHOW_ALL_PERSONS); + } else { + requireNonNull(profPredicate); + model.updateFilteredProfList(profPredicate); + } + for (Person person : model.getFilteredProfList()) { + model.addPerson(person); + } + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/seedu/address/logic/parser/BookCommandParser.java b/src/main/java/seedu/address/logic/parser/BookCommandParser.java index afd90b6f0fe..f028e841b67 100644 --- a/src/main/java/seedu/address/logic/parser/BookCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/BookCommandParser.java @@ -28,14 +28,23 @@ public class BookCommandParser implements Parser { public BookCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES); - - if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME) + System.out.println("START TEST"); + if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, BookCommand.MESSAGE_USAGE)); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES); +// if (argMultimap.getValue(PREFIX_NOTES).isPresent()) { +// System.out.println("TEST"); +// if (argMultimap.getValue(PREFIX_NOTES) == null) { +// throw new ParseException("Booking notes missing"); +// } +// } else { +// System.out.println("TEST ELSE"); +// } + Description description = ParserUtil.parseBookingName(argMultimap.getValue(PREFIX_DESCRIPTION).get()); StartTime start = ParserUtil.parseStartTime(argMultimap.getValue(PREFIX_START_TIME).get()); EndTime end = ParserUtil.parseEndTime(argMultimap.getValue(PREFIX_END_TIME).get()); From b9241925324dd5b68e61fb569bb519cd0ba86a7e Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Sun, 7 Apr 2024 22:55:55 +0800 Subject: [PATCH 02/12] Fix Wrong Error message displayed for empty note. Correct error message now shown on empty note field. clear #141 --- .../address/logic/commands/BookCommand.java | 1 + .../address/logic/parser/BookCommandParser.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/BookCommand.java b/src/main/java/seedu/address/logic/commands/BookCommand.java index 4d8017eb3df..e634a4f61ae 100644 --- a/src/main/java/seedu/address/logic/commands/BookCommand.java +++ b/src/main/java/seedu/address/logic/commands/BookCommand.java @@ -32,6 +32,7 @@ public class BookCommand extends Command { + PREFIX_START_TIME + "2023-12-31 19:00 " + PREFIX_END_TIME + "2023-12-31 23:00 " + PREFIX_NOTES + "Bring cake"; + public static final String MESSAGE_NOTE_MISSING = "Error: Please fill in a non-empty note!"; private final Booking toAdd; /** diff --git a/src/main/java/seedu/address/logic/parser/BookCommandParser.java b/src/main/java/seedu/address/logic/parser/BookCommandParser.java index f028e841b67..13c4bd08f45 100644 --- a/src/main/java/seedu/address/logic/parser/BookCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/BookCommandParser.java @@ -6,6 +6,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTES; import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; +import java.util.Optional; import java.util.stream.Stream; import seedu.address.logic.commands.BookCommand; @@ -28,22 +29,18 @@ public class BookCommandParser implements Parser { public BookCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES); - System.out.println("START TEST"); - if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES) + + if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, BookCommand.MESSAGE_USAGE)); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES); -// if (argMultimap.getValue(PREFIX_NOTES).isPresent()) { -// System.out.println("TEST"); -// if (argMultimap.getValue(PREFIX_NOTES) == null) { -// throw new ParseException("Booking notes missing"); -// } -// } else { -// System.out.println("TEST ELSE"); -// } + // If note field is empty + if (argMultimap.getValue(PREFIX_NOTES).isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, BookCommand.MESSAGE_NOTE_MISSING)); + } Description description = ParserUtil.parseBookingName(argMultimap.getValue(PREFIX_DESCRIPTION).get()); StartTime start = ParserUtil.parseStartTime(argMultimap.getValue(PREFIX_START_TIME).get()); From 6e34c300b5b985a2a6f47d9b35029f446543cea5 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Sun, 7 Apr 2024 23:04:02 +0800 Subject: [PATCH 03/12] Fix Book command that accepts dates that do not exist Previously invalid dates like Feb 31 were accepted, now Strict ResolverStyle was used to disallow this. --- .../java/seedu/address/logic/parser/BookCommandParser.java | 2 +- src/main/java/seedu/address/model/booking/EndTime.java | 5 ++++- src/main/java/seedu/address/model/booking/StartTime.java | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/BookCommandParser.java b/src/main/java/seedu/address/logic/parser/BookCommandParser.java index 13c4bd08f45..ba18d3a03e2 100644 --- a/src/main/java/seedu/address/logic/parser/BookCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/BookCommandParser.java @@ -29,7 +29,7 @@ public class BookCommandParser implements Parser { public BookCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_NOTES); - + if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_START_TIME, PREFIX_END_TIME) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, BookCommand.MESSAGE_USAGE)); diff --git a/src/main/java/seedu/address/model/booking/EndTime.java b/src/main/java/seedu/address/model/booking/EndTime.java index 316bc924d5e..53b21c0c218 100644 --- a/src/main/java/seedu/address/model/booking/EndTime.java +++ b/src/main/java/seedu/address/model/booking/EndTime.java @@ -5,6 +5,8 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; + /** * Represents a Booking's end time in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidEndTime(String)} @@ -13,7 +15,8 @@ public class EndTime { public static final String MESSAGE_CONSTRAINTS = "End times must be in the format of YYYY-MM-DD HH:MM " + "(ISO_LOCAL_DATE_TIME)."; - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm"); + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm") + .withResolverStyle(ResolverStyle.STRICT);; public final String endTimeString; public final LocalDateTime endTime; diff --git a/src/main/java/seedu/address/model/booking/StartTime.java b/src/main/java/seedu/address/model/booking/StartTime.java index 9cf27066d43..be056a09e66 100644 --- a/src/main/java/seedu/address/model/booking/StartTime.java +++ b/src/main/java/seedu/address/model/booking/StartTime.java @@ -5,6 +5,8 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; + /** * Represents a Booking's start time in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidStartTime(String)} @@ -13,7 +15,8 @@ public class StartTime { public static final String MESSAGE_CONSTRAINTS = "Start times must be in the format of YYYY-MM-DD HH:MM " + "(ISO_LOCAL_DATE_TIME)."; - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm"); + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm") + .withResolverStyle(ResolverStyle.STRICT); public final String startTimeString; public final LocalDateTime startTime; From cbbeb1f68a763181643dd8bd5d084b15b93288e1 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Sun, 7 Apr 2024 23:37:39 +0800 Subject: [PATCH 04/12] Revert some test cases to original StartTime cannot be modified because some test cases will break, hence fix was reverted --- .../address/logic/parser/BookCommandParser.java | 1 - .../seedu/address/model/booking/EndTime.java | 4 +--- .../seedu/address/model/booking/StartTime.java | 4 +--- .../seedu/address/testutil/BookingBuilder.java | 4 ++-- .../seedu/address/testutil/TypicalBookings.java | 16 ++++++++-------- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/BookCommandParser.java b/src/main/java/seedu/address/logic/parser/BookCommandParser.java index ba18d3a03e2..2b0cb22d46b 100644 --- a/src/main/java/seedu/address/logic/parser/BookCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/BookCommandParser.java @@ -6,7 +6,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTES; import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; -import java.util.Optional; import java.util.stream.Stream; import seedu.address.logic.commands.BookCommand; diff --git a/src/main/java/seedu/address/model/booking/EndTime.java b/src/main/java/seedu/address/model/booking/EndTime.java index 53b21c0c218..c9a747cba01 100644 --- a/src/main/java/seedu/address/model/booking/EndTime.java +++ b/src/main/java/seedu/address/model/booking/EndTime.java @@ -5,7 +5,6 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import java.time.format.ResolverStyle; /** * Represents a Booking's end time in the address book. @@ -15,8 +14,7 @@ public class EndTime { public static final String MESSAGE_CONSTRAINTS = "End times must be in the format of YYYY-MM-DD HH:MM " + "(ISO_LOCAL_DATE_TIME)."; - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm") - .withResolverStyle(ResolverStyle.STRICT);; + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); public final String endTimeString; public final LocalDateTime endTime; diff --git a/src/main/java/seedu/address/model/booking/StartTime.java b/src/main/java/seedu/address/model/booking/StartTime.java index be056a09e66..e03a37b8942 100644 --- a/src/main/java/seedu/address/model/booking/StartTime.java +++ b/src/main/java/seedu/address/model/booking/StartTime.java @@ -5,7 +5,6 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import java.time.format.ResolverStyle; /** * Represents a Booking's start time in the address book. @@ -15,8 +14,7 @@ public class StartTime { public static final String MESSAGE_CONSTRAINTS = "Start times must be in the format of YYYY-MM-DD HH:MM " + "(ISO_LOCAL_DATE_TIME)."; - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d HH:mm") - .withResolverStyle(ResolverStyle.STRICT); + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); public final String startTimeString; public final LocalDateTime startTime; diff --git a/src/test/java/seedu/address/testutil/BookingBuilder.java b/src/test/java/seedu/address/testutil/BookingBuilder.java index faf02f6e8ee..74e159b5c96 100644 --- a/src/test/java/seedu/address/testutil/BookingBuilder.java +++ b/src/test/java/seedu/address/testutil/BookingBuilder.java @@ -13,8 +13,8 @@ public class BookingBuilder { public static final String DEFAULT_DESCRIPTION = "Default booking description"; - public static final String DEFAULT_START_TIME = "2023-12-31 19:00"; - public static final String DEFAULT_END_TIME = "2023-12-31 21:00"; + public static final String DEFAULT_START_TIME = "2023-12-22 19:00"; + public static final String DEFAULT_END_TIME = "2023-12-22 21:00"; public static final String DEFAULT_NOTE = "Hello World!"; private Description description; diff --git a/src/test/java/seedu/address/testutil/TypicalBookings.java b/src/test/java/seedu/address/testutil/TypicalBookings.java index f6990adadda..dd6a4be0851 100644 --- a/src/test/java/seedu/address/testutil/TypicalBookings.java +++ b/src/test/java/seedu/address/testutil/TypicalBookings.java @@ -20,26 +20,26 @@ public class TypicalBookings { public static final Booking CAREER_ADVISORY = new BookingBuilder() .withDescription("Career advisory consult") - .withStartTime("2024-1-31 11:00") - .withEndTime("2024-1-31 12:00") + .withStartTime("2024-01-12 11:00") + .withEndTime("2024-01-12 12:00") .build(); public static final Booking CS2103T_CONSULT = new BookingBuilder() .withDescription("CS2103T consult") - .withStartTime("2024-3-31 14:00") - .withEndTime("2024-3-31 16:00") + .withStartTime("2024-03-09 14:00") + .withEndTime("2024-03-09 16:00") .build(); public static final Booking CS2101_CONSULT = new BookingBuilder() .withDescription("CS2101 consult") - .withStartTime("2024-3-24 14:00") - .withEndTime("2024-3-24 16:00") + .withStartTime("2024-03-24 14:00") + .withEndTime("2024-03-24 16:00") .build(); public static final Booking CS2109S_CONSULT = new BookingBuilder() .withDescription("CS2109 consult") - .withStartTime("2024-2-22 11:00") - .withEndTime("2024-2-22 13:00") + .withStartTime("2024-05-22 11:00") + .withEndTime("2024-05-22 13:00") .build(); public static final Booking GENERIC_BOOKING = new BookingBuilder() From db08e29a451a2bfade55ab0d4f7ccd8fe1a21504 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Sun, 7 Apr 2024 23:59:43 +0800 Subject: [PATCH 05/12] Fix UpdateCommand Message to reflect older command that was updated Update test cases to reflect this change clear #151 --- .../address/logic/commands/UpdateCommand.java | 2 +- .../logic/commands/UpdateCommandTest.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/UpdateCommand.java b/src/main/java/seedu/address/logic/commands/UpdateCommand.java index 7be28a52479..52265f23499 100644 --- a/src/main/java/seedu/address/logic/commands/UpdateCommand.java +++ b/src/main/java/seedu/address/logic/commands/UpdateCommand.java @@ -80,7 +80,7 @@ public CommandResult execute(Model model) throws CommandException { model.setBooking(bookingToUpdate, updatedBooking); model.updateFilteredBookingList(PREDICATE_SHOW_ALL_BOOKINGS); - return new CommandResult(String.format(MESSAGE_UPDATE_BOOKING_SUCCESS, Messages.format(updatedBooking))); + return new CommandResult(String.format(MESSAGE_UPDATE_BOOKING_SUCCESS, Messages.format(bookingToUpdate))); } /** diff --git a/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java b/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java index 53be0f25380..a9a8bb2010b 100644 --- a/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java @@ -38,17 +38,18 @@ public class UpdateCommandTest { @Test public void execute_allFieldsSpecifiedUnfilteredList_success() { + Booking originalBooking = model.getFilteredBookingList().get(0); Booking updatedBooking = new BookingBuilder().build(); UpdateBookingDescriptor descriptor = new UpdateBookingDescriptorBuilder(updatedBooking).build(); UpdateCommand updateCommand = new UpdateCommand(INDEX_FIRST_BOOKING, descriptor); String expectedMessage = String.format(UpdateCommand.MESSAGE_UPDATE_BOOKING_SUCCESS, - Messages.format(updatedBooking)); + Messages.format(originalBooking)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), - new ProfData(model.getProfData()), - new UserPrefs()); - expectedModel.setBooking(model.getFilteredBookingList().get(0), updatedBooking); + new ProfData(model.getProfData()), + new UserPrefs()); + expectedModel.setBooking(originalBooking, updatedBooking); assertCommandSuccess(updateCommand, model, expectedMessage, expectedModel); } @@ -69,16 +70,17 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { UpdateCommand updateCommand = new UpdateCommand(indexLastBooking, descriptor); String expectedMessage = String.format(UpdateCommand.MESSAGE_UPDATE_BOOKING_SUCCESS, - Messages.format(updatedBooking)); + Messages.format(lastBooking)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), - new ProfData(model.getProfData()), - new UserPrefs()); + new ProfData(model.getProfData()), + new UserPrefs()); expectedModel.setBooking(lastBooking, updatedBooking); assertCommandSuccess(updateCommand, model, expectedMessage, expectedModel); } + @Test public void execute_noFieldSpecifiedUnfilteredList_success() { UpdateCommand updateCommand = new UpdateCommand(INDEX_FIRST_BOOKING, new UpdateBookingDescriptor()); @@ -102,19 +104,21 @@ public void execute_filteredList_success() { Booking updatedBooking = new BookingBuilder(bookingInFilteredList).withDescription(VALID_BOOKING_DESCRIPTION).build(); UpdateCommand updateCommand = new UpdateCommand(INDEX_FIRST_BOOKING, - new UpdateBookingDescriptorBuilder().withDescription(VALID_BOOKING_DESCRIPTION).build()); + new UpdateBookingDescriptorBuilder() + .withDescription(VALID_BOOKING_DESCRIPTION).build()); String expectedMessage = String.format(UpdateCommand.MESSAGE_UPDATE_BOOKING_SUCCESS, - Messages.format(updatedBooking)); + Messages.format(bookingInFilteredList)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), - new ProfData(model.getProfData()), - new UserPrefs()); - expectedModel.setBooking(model.getFilteredBookingList().get(0), updatedBooking); + new ProfData(model.getProfData()), + new UserPrefs()); + expectedModel.setBooking(bookingInFilteredList, updatedBooking); assertCommandSuccess(updateCommand, model, expectedMessage, expectedModel); } + @Test public void execute_duplicateBookingUnfilteredList_failure() { Booking firstBooking = model.getFilteredBookingList().get(INDEX_FIRST_BOOKING.getZeroBased()); From bceeb00a54d256ca1556979d866f60fd5896328a Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Mon, 8 Apr 2024 00:17:43 +0800 Subject: [PATCH 06/12] Update UserGuide to fix PED documentation bugs Newlines added in FAQ, clear was changed to cancel to reflect the correct command --- docs/UserGuide.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index e340121a325..71479daa302 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -538,12 +538,12 @@ Done searching for your bookings with your favourite professor? Lets display all view ``` -#### Clearing all bookings entries : `clear` +#### Clearing all bookings entries : `cancel -a` Want a fresh start? Quickly clears all your bookings with: ``` - clear + cancel -a ```
@@ -563,7 +563,7 @@ Dook comes preinstalled with a light and dark theme. ![Light Theme](images/lighttheme.png) -Format: `-bg THEME(light/dark)` +Format: `theme -bg light/dark` * changes the current theme to either dark/light * dark theme is the *default* on a new launch * Dook remembers your preferences!, it loads the most recent selected theme on launch. @@ -604,7 +604,7 @@ AddressBook data are saved automatically after any command that changes the data ### Editing the data file -AddressBook data are saved automatically as a JSON file `[JAR file location]/data/addressbook.json`. Advanced users are welcome to update data directly by editing that data file. +AddressBook data are saved automatically as a JSON file:
`[JAR file location]/data/addressbook.json`.
Advanced users are welcome to update data directly by editing that data file.
:exclamation: **Caution:** If your changes to the data file makes its format invalid, AddressBook will discard all data and start with an empty data file at the next run. Hence, it is recommended to take a backup of the file before editing it.
@@ -615,17 +615,17 @@ Furthermore, certain edits can cause the AddressBook to behave in unexpected way ## FAQ -**Q**: How do I install Java 11? +**Q**: How do I install Java 11?
**A**: Follow this [link](https://docs.oracle.com/en/java/javase/11/install/overview-jdk-installation.html#GUID-8677A77F-231A-40F7-98B9-1FD0B48C346A) for steps to download Java 11. **Q**: How do I transfer my data to another Computer?
**A**: Go to the application's home directory and copy the `data/addressbook.json` file containing your data into the empty data folder created by Dook on the other computer. -**Q**: Oh no! I have accidentally closed Dook without using the `exit` command? Do I lose all my data? +**Q**: Oh no! I have accidentally closed Dook without using the `exit` command? Do I lose all my data?
**A**: Not to worry! Dook automatically saves all data after every change, so no data will be lost! -**Q**: Do I need Internet connection to use Dook? +**Q**: Do I need Internet connection to use Dook?
**A**: Nope! Dook works fully offline and online! -------------------------------------------------------------------------------------------------------------------- From 4274df4572734eb866c09af87a4a498f1faf4777 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Mon, 8 Apr 2024 00:22:31 +0800 Subject: [PATCH 07/12] Update UserGuide to reflect Compulsory status of Notes section in booking Pervious iteration of UserGuide was ambiguous in that notes was optional, resulting in many bugs from testers --- docs/UserGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 71479daa302..5ff6c6b64a6 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -470,7 +470,7 @@ If you want to remind yourself of your consult tomorrow, you can add it to Dook. | **DESCRIPTION** | Must be non-null and unique | | **START_TIME** | Must follow format of `2023-12-31 19:00` | | **END_TIME** | Must follow format of `2023-12-31 19:00` | -| **NOTE** | Optional | +| **NOTE** | Must be non-null and unique | Examples: * `book -n CS2101 Consult -s 2023-12-31 19:00 -e 2023-12-31 23:00 -note DO HOMEWORK` From d51a4f47535f1d75808adad4c3dbe41f81d2563e Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Mon, 8 Apr 2024 00:26:02 +0800 Subject: [PATCH 08/12] Change one-line in userguide to reflect correct `book` command Remove ambiguity in book command which was reflected in PED issues --- docs/UserGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 5ff6c6b64a6..d0abaef3c9f 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -460,7 +460,7 @@ This command is **irreversible**, the deleted contact information will be lost! If you want to remind yourself of your consult tomorrow, you can add it to Dook. ``` --n DESCRIPTION -s START_TIME -e END_TIME -note NOTE +book -n DESCRIPTION -s START_TIME -e END_TIME -note NOTE ``` * Duplicate bookings are not allowed! This means that across two bookings, you cannot have all four params to be the exact same. * For now: start and end time formats must be in `yyyy-mm-d hh:mm` (we are working to expand this!) From 64170ab24becfea8d8a3d1800743497a009f5773 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Mon, 8 Apr 2024 12:08:58 +0800 Subject: [PATCH 09/12] Rename addressbook.jar to Dook.jar to match convention in UG. Default jar file name was previously used which caused discrepancy in the UG instruction.# --- build.gradle | 2 +- .../logic/parser/AddProfCommandParser.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/java/seedu/address/logic/parser/AddProfCommandParser.java diff --git a/build.gradle b/build.gradle index 6a9b7c9831b..2e7639cebe5 100644 --- a/build.gradle +++ b/build.gradle @@ -71,7 +71,7 @@ dependencies { } shadowJar { - archiveFileName = 'addressbook.jar' + archiveFileName = 'Dook.jar' } processResources { diff --git a/src/main/java/seedu/address/logic/parser/AddProfCommandParser.java b/src/main/java/seedu/address/logic/parser/AddProfCommandParser.java new file mode 100644 index 00000000000..f54e057655b --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddProfCommandParser.java @@ -0,0 +1,55 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; + +import java.util.Arrays; +import java.util.stream.Stream; + +import seedu.address.logic.commands.AddProfCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.NameContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new AddProfCommand object + */ +public class AddProfCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddProfCommand + * and returns an AddProfCommand object for execution. + * + * @throws ParseException if the user input does not conform to the expected format + */ + public AddProfCommand parse(String args) throws ParseException { + // Trim and check if the argument is exactly "-a" for adding all professors + String trimmedArgs = args.trim(); + if (trimmedArgs.equals("-a")) { + // Add all professors + return new AddProfCommand(); + } else { + // Process adding professors by name + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME); + + if (!arePrefixesPresent(argMultimap, PREFIX_NAME) || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddProfCommand.MESSAGE_USAGE)); + } + + String nameString = argMultimap.getValue(PREFIX_NAME).get().trim(); + if (nameString.isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddProfCommand.MESSAGE_USAGE)); + } + + String[] nameKeywords = nameString.split("\\s+"); + return new AddProfCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + } + } + + /** + * Returns true if none of the prefixes contains empty {@code Optional} values in the given + * {@code ArgumentMultimap}. + */ + private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } +} From 89b53b09ce6ab1860ee7c78e5197ade2812d8dc4 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Mon, 8 Apr 2024 12:18:23 +0800 Subject: [PATCH 10/12] Fix minor nit in PED issues where `find` only works on contact name Changes include specifying in user guide that only find works on name field, and future iterations would involve finding by other fields as well --- docs/UserGuide.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index d0abaef3c9f..0f7c74383e0 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -383,6 +383,13 @@ Format: `find KEYWORD [MORE_KEYWORDS]` * Persons matching at least one keyword will be returned (i.e. `OR` search). e.g. `Hans Bo` will return `Hans Gruber`, `Bo Yang` +
+:information_source: **Information** + +For now, we can only `find` contacts by name - future implementations would include finding by other fields as well, +so stay tuned! +
+ Examples: * `find John` returns `john` and `John Doe` * `find alex david` returns `Alex Yeoh`, `David Li`
From 7d9ec3d5660ef22908ae92e7714ef3993decf97f Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Mon, 8 Apr 2024 14:24:12 +0800 Subject: [PATCH 11/12] Removed Duplicate AddProfCommand files Merge conflict cause duplicate files to be pushed to branch, latest commit reverts this change --- .../logic/commands/AddProfCommand.java | 63 ------------------- .../logic/parser/AddProfCommandParser.java | 55 ---------------- 2 files changed, 118 deletions(-) delete mode 100644 src/main/java/seedu/address/logic/commands/AddProfCommand.java delete mode 100644 src/main/java/seedu/address/logic/parser/AddProfCommandParser.java diff --git a/src/main/java/seedu/address/logic/commands/AddProfCommand.java b/src/main/java/seedu/address/logic/commands/AddProfCommand.java deleted file mode 100644 index 0af1fe336c2..00000000000 --- a/src/main/java/seedu/address/logic/commands/AddProfCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package seedu.address.logic.commands; - -import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; - -import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.Model; -import seedu.address.model.person.NameContainsKeywordsPredicate; -import seedu.address.model.person.Person; - -/** - * Adds professors to the address book. Can add all professors or those matching a given name. - */ -public class AddProfCommand extends Command { - public static final String COMMAND_WORD = "prof"; - - public static final String MESSAGE_SUCCESS = "Professors Added!"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds professors to the address book.\n" - + "Parameters: -a (to add all professors) or " - + PREFIX_NAME + "NAME (to add professors by name)\n" - + "Example: " + COMMAND_WORD + " -a\n" - + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "Aaron"; - - private final boolean addAll; - private final NameContainsKeywordsPredicate profPredicate; - - /** - * Constructor for creating an {@code AddProfCommand} to add all professors. - * This constructor sets the command to add all professors without filtering by name. - */ - public AddProfCommand() { - this.addAll = true; - this.profPredicate = null; - } - - /** - * Constructor for creating an {@code AddProfCommand} with a specific name filter. - * This constructor sets the command to add professors filtered by the specified name predicate. - * - * @param profPredicate The {@code NameContainsKeywordsPredicate} used for filtering professors by name. - */ - public AddProfCommand(NameContainsKeywordsPredicate profPredicate) { - this.profPredicate = profPredicate; - this.addAll = false; - } - - @Override - public CommandResult execute(Model model) throws CommandException { - requireNonNull(model); - if (addAll) { - model.updateFilteredProfList(PREDICATE_SHOW_ALL_PERSONS); - } else { - requireNonNull(profPredicate); - model.updateFilteredProfList(profPredicate); - } - for (Person person : model.getFilteredProfList()) { - model.addPerson(person); - } - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(MESSAGE_SUCCESS); - } -} diff --git a/src/main/java/seedu/address/logic/parser/AddProfCommandParser.java b/src/main/java/seedu/address/logic/parser/AddProfCommandParser.java deleted file mode 100644 index f54e057655b..00000000000 --- a/src/main/java/seedu/address/logic/parser/AddProfCommandParser.java +++ /dev/null @@ -1,55 +0,0 @@ -package seedu.address.logic.parser; - -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; - -import java.util.Arrays; -import java.util.stream.Stream; - -import seedu.address.logic.commands.AddProfCommand; -import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; - -/** - * Parses input arguments and creates a new AddProfCommand object - */ -public class AddProfCommandParser implements Parser { - - /** - * Parses the given {@code String} of arguments in the context of the AddProfCommand - * and returns an AddProfCommand object for execution. - * - * @throws ParseException if the user input does not conform to the expected format - */ - public AddProfCommand parse(String args) throws ParseException { - // Trim and check if the argument is exactly "-a" for adding all professors - String trimmedArgs = args.trim(); - if (trimmedArgs.equals("-a")) { - // Add all professors - return new AddProfCommand(); - } else { - // Process adding professors by name - ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME); - - if (!arePrefixesPresent(argMultimap, PREFIX_NAME) || !argMultimap.getPreamble().isEmpty()) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddProfCommand.MESSAGE_USAGE)); - } - - String nameString = argMultimap.getValue(PREFIX_NAME).get().trim(); - if (nameString.isEmpty()) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddProfCommand.MESSAGE_USAGE)); - } - - String[] nameKeywords = nameString.split("\\s+"); - return new AddProfCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); - } - } - - /** - * Returns true if none of the prefixes contains empty {@code Optional} values in the given - * {@code ArgumentMultimap}. - */ - private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { - return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); - } -} From 634e85419441666b64ebb8581cf76f615858a983 Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Tue, 9 Apr 2024 11:45:20 +0800 Subject: [PATCH 12/12] Removed unique note in book command Reformat certain images in UserGuide, and fixed some grammar issues --- docs/UserGuide.md | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 0f7c74383e0..d13a2a70dc4 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -477,7 +477,7 @@ book -n DESCRIPTION -s START_TIME -e END_TIME -note NOTE | **DESCRIPTION** | Must be non-null and unique | | **START_TIME** | Must follow format of `2023-12-31 19:00` | | **END_TIME** | Must follow format of `2023-12-31 19:00` | -| **NOTE** | Must be non-null and unique | +| **NOTE** | Must be non-null | Examples: * `book -n CS2101 Consult -s 2023-12-31 19:00 -e 2023-12-31 23:00 -note DO HOMEWORK` @@ -566,38 +566,50 @@ Please use this command with caution! Dook comes preinstalled with a light and dark theme. -![Dark Theme](images/darktheme.png) - -![Light Theme](images/lighttheme.png) - Format: `theme -bg light/dark` -* changes the current theme to either dark/light -* dark theme is the *default* on a new launch -* Dook remembers your preferences!, it loads the most recent selected theme on launch. + +* Changes the current theme to either dark/light +* Dark theme is the *default* on a new launch +* Dook remembers your preferences, it loads the most recent selected theme on launch. Examples: * `theme -bg light` -Any unknown theme will be met with an error message +Below shows the application before executing `theme -bg light`: + +![Dark Theme](images/darktheme.png) + +Below shows the application after executing `theme -bg light`: + +![Light Theme](images/lighttheme.png) + +Below shows the error message upon executing an invalid theme: ![Theme_Command_Failure](images/themefailure.png) + +
:information_source: **Information** + New themes are currently being added. +
+ ### Adding aliases in Dook : `alias` -#### **Warning! For advance users only** +
-Dook allows the aliasing of whole commands to any input of the users choice +**:exclamation: For advanced users only!**
-Format: `-al NEW_COMMAND -r COMMAND_TO_REPLACE` +
-* commands like *theme -bg light* can be aliased to just *light* for convenience -* aliases **cannot** be deleted as of the current version -* aliases immediate tries to execute the replaced command, *does not work as a macro* -* therefore aliases such as replacing **add -n** to **addn** does not work as intended, as add -n will be -immediately executed and met by an error +Dook allows the aliasing of whole commands to any input of the users choice: + +Format: `-al NEW_COMMAND -r COMMAND_TO_REPLACE` +* Commands like *theme -bg light* can be aliased to just *light* for convenience +* Aliases **cannot** be deleted as of the current version +* Aliases immediately tries to execute the replaced command, *does not work as a macro* +* Aliases such as replacing **add -n** to **addn** does not work as intended ### Exiting the program : `exit`