diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 7d817b6b9e..8b065e8603 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -163,6 +163,45 @@ and modifications. The following sequence diagram shows how the view transaction operation works: +### `edit` Transaction Feature + +#### I. Architecture-Level Design +This section details the components involved in the `edit` transaction feature: +1. **Parser**: Interprets user input and creates an `EditCommand` object with the appropriate parameters. +2. **EditCommand**: Inherits from the `Command` class, encapsulating the "edit" action along with the index and the new transaction details. +3. **Nuscents**: The main class that invokes the `execute()` method of `EditCommand`. +4. **TransactionList**: Manages a collection of transactions and facilitates the replacement of a specific transaction. +5. **Transaction**: The superclass for different types of transactions such as `Expense` and `Allowance`. +6. **UI**: Manages interactions with the user and displays messages regarding the editing process. + +#### II. Component-Level Design +Here's how each component plays a role in the `edit` transaction feature: +1. **Parser**: Extracts the index and transaction details from the input and uses other parsing methods to create a `Transaction` object. +2. **EditCommand**: Contains the logic to replace an existing transaction in the `TransactionList`. +3. **Nuscents**: Calls the `execute()` method of `EditCommand` and handles exceptions that may arise. +4. **TransactionList**: Provides the `editTransaction(index, transaction)` method to update transactions at a specific index. +5. **Transaction**: Abstract representation of a financial record that can be edited. +6. **UI**: Outputs the result of the edit operation and any error messages. + +#### III. Alternatives Considered +An alternative design considered was to have `EditCommand` interact directly with `Transaction` objects to modify their fields. However, this approach was discarded in favor of having a clear separation where `TransactionList` manages all transactions, maintaining encapsulation and single responsibility principles. + +#### IV. Usage Scenario Example +**Step 1**: User starts the application, and `TransactionList` is initialized with existing transactions. + +**Step 2**: The user inputs `edit 2 expense /amt 100 /date 01-01-2023 /desc Movie night`. The `Parser` reads the input, separating the index from the rest of the transaction details. + +**Step 3**: `Parser` calls `parseExpense` to create an `Expense` object and then constructs an `EditCommand` with the index and the new `Expense`. + +**Step 4**: `Nuscents` receives and invokes the `EditCommand`'s `execute()` method. + +**Step 5**: Inside `execute()`, `EditCommand` uses `TransactionList`'s `editTransaction(index, transaction)` to replace the existing transaction. + +**Step 6**: `TransactionList` updates the transaction at the given index. If the index is invalid, an exception is thrown. + +**Step 7**: Upon successful update, `UI` displays a confirmation message. If an error occurs, an error message is shown instead. + + ### `helpCommand` Feature #### I. Architecture-Level Design diff --git a/src/main/java/seedu/nuscents/ui/Messages.java b/src/main/java/seedu/nuscents/ui/Messages.java index 1389eb6ce0..4342d3361d 100644 --- a/src/main/java/seedu/nuscents/ui/Messages.java +++ b/src/main/java/seedu/nuscents/ui/Messages.java @@ -38,7 +38,6 @@ public class Messages { public static final String MESSAGE_INVALID_INDEX = "OOPS!!! This is an invalid transaction index."; public static final String MESSAGE_INVALID_INDEX_ARGUMENTS = "OOPS!!! The input should consist only of digits."; public static final String MESSAGE_EMPTY_LIST = "You have not made any transactions!"; - public static final String MESSAGE_EMPTY_KEYWORD = "OOPS!!! The keyword of a find command cannot be empty."; public static final String MESSAGE_EMPTY_BUDGET = "OOPS!!! The budget amount cannot be empty."; public static final String MESSAGE_INVALID_BUDGET = "OOPS!!! The budget amount requires a +ve valid float value"; public static final String MESSAGE_INVALID_BUDGET_FLOAT_DP = "OOPS!!! The budget amount cannot exceed 2 d.p."; diff --git a/src/test/java/seedu/nuscents/parser/ParserTest.java b/src/test/java/seedu/nuscents/parser/ParserTest.java index e31c004bb8..2fa1a52d0d 100644 --- a/src/test/java/seedu/nuscents/parser/ParserTest.java +++ b/src/test/java/seedu/nuscents/parser/ParserTest.java @@ -288,6 +288,17 @@ public void parseFilterCategory_invalidCategory_exceptionThrown() throws Nuscent assertEquals(Messages.MESSAGE_UNKNOWN_FILTER_CATEGORY, exception.getMessage()); } + @Test + public void parseEdit_emptyArguments_exceptionThrown() { + String input = "edit 2"; + Exception exception = assertThrows(NuscentsException.class, () -> { + Parser.parseEdit(input); + }); + assertEquals(Messages.MESSAGE_EMPTY_EDIT, exception.getMessage()); + } + + + @Test public void parseCommand_helpCommandWithCorrectInput_returnsHelpCommand() throws Exception { Command result = Parser.parseCommand("help", null);