Skip to content

Commit

Permalink
Merge pull request #286 from awesomesjh/update-rename
Browse files Browse the repository at this point in the history
Update rename
  • Loading branch information
rismm committed Apr 15, 2024
2 parents cc9515a + bbbfea9 commit 8f02ea8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ The following sequence diagram shows the execution of a RenameCommand<br>

1. The `SuperTracker` class calls the `execute` method of `RenameCommand`
2. The item object of the item to be renamed is obtained from `Inventory`
3. The quantity, price and expiry date are obtained from the item
3. The old name, quantity, price and expiry date are obtained from the item
4. A new `Item` object with the given parameters (newName, quantity, price, expiry date) is created and returned to `RenameCommand`
5. The `delete` method of the `Inventory` class is called to delete the old item
6. The `put` method of the `Inventory` class is called to put the new item into the inventory
Expand Down
7 changes: 6 additions & 1 deletion docs/uml-diagrams/RenameCommand.puml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ activate Inventory #d5eac2
Inventory --> RenameCommand : oldItem:Item
deactivate Inventory

RenameCommand -> oldItem: getName()
activate oldItem #ffa1a1
oldItem --> RenameCommand: oldName:String
deactivate oldItem

RenameCommand -> oldItem: getQuantity()
activate oldItem #ffa1a1
oldItem --> RenameCommand: quantity:int
Expand Down Expand Up @@ -111,7 +116,7 @@ activate Inventory #d5eac2
Inventory --> RenameCommand
deactivate Inventory

RenameCommand -> Ui : renameCommandSuccess(item:Item)
RenameCommand -> Ui : renameCommandSuccess(newItem:Item, oldName:String)
activate Ui #e5c2ea
Ui --> RenameCommand
deactivate Ui
Expand Down
Binary file modified docs/uml-diagrams/RenameCommandSequence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/main/java/supertracker/command/RenameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void execute() {
assert Inventory.contains(name);

Item oldItem = Inventory.get(name);
String oldName = oldItem.getName();
int quantity = oldItem.getQuantity();
double price = oldItem.getPrice();
LocalDate expiryDate = oldItem.getExpiryDate();
Expand All @@ -40,7 +41,7 @@ public void execute() {
Inventory.delete(name);

Inventory.put(newName, newItem);
Ui.renameCommandSuccess(newItem, name);
Ui.renameCommandSuccess(newItem, oldName);

try {
ItemStorage.saveData();
Expand Down

0 comments on commit 8f02ea8

Please sign in to comment.