Skip to content

Commit

Permalink
Merge pull request #79 from chonghaoen/add-cancel-order-command
Browse files Browse the repository at this point in the history
Fix bug in GUI where order tag is not changed
  • Loading branch information
chonghaoen authored Mar 26, 2024
2 parents d840f96 + 9f02cee commit f285db9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT_QUANTITY;

import java.util.ArrayList;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand Down Expand Up @@ -87,11 +85,6 @@ public CommandResult execute(Model model) throws CommandException {

Person customer = lastOrder.getCustomer();
model.addOrder(lastOrder, customer);
ArrayList<Order> currentOrders = customer.getOrders();
currentOrders.add(lastOrder);
customer.setOrders(currentOrders);
model.setPerson(personToEdit, customer);


return new CommandResult(generateSuccessMessage());
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.List;

import javafx.collections.ObservableList;
Expand Down Expand Up @@ -93,6 +94,13 @@ public void addPerson(Person p) {
public void addOrder(Order order) {
int orderCounter = orders.getOrderIdCounter();
order.setID(orderCounter);

Person editedCustomer = order.getCustomer();
ArrayList<Order> listToEdit = editedCustomer.getOrders();
listToEdit.add(order);
editedCustomer.setOrders(listToEdit);
this.setPerson(order.getCustomer(), editedCustomer);

orders.addOrder(order);
}

Expand Down Expand Up @@ -150,6 +158,14 @@ public void removePerson(Person key) {
* @param id index of order to remove
*/
public void removeOrder(int id) {
Order orderToDelete = this.findOrderByIndex(id);

Person editedCustomer = orderToDelete.getCustomer();
ArrayList<Order> listToEdit = editedCustomer.getOrders();
listToEdit.remove(orderToDelete);
editedCustomer.setOrders(listToEdit);
this.setPerson(orderToDelete.getCustomer(), editedCustomer);

orders.deleteOrder(id);
}

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/seedu/address/model/order/OrderList.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,8 @@ public void deleteOrder(int toDelete) {
if (oldOrder == null) {
throw new OrderNotFoundException();
}
Person respectiveCustomer = oldOrder.getCustomer();
//if (respectiveCustomer == null) {
// throw new PersonNotFoundException();
//}
orderList.remove(toDelete);
internalList.remove(oldOrder);
//respectiveCustomer.deleteOrder(oldOrder.getId());
}

/**
Expand Down

0 comments on commit f285db9

Please sign in to comment.