Skip to content

Commit

Permalink
Update FindOrderByDate class, add PostponeOrder class, delete StartNe…
Browse files Browse the repository at this point in the history
…wOrder class, update methods in Parser for parsing order commands.
  • Loading branch information
Yu Jiahan committed Oct 16, 2019
1 parent 710e4b0 commit 61a3f68
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 167 deletions.
6 changes: 5 additions & 1 deletion src/main/java/duke/orderCommand/FindOrderByDate.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.orderCommand;

import duke.command.Command;
import duke.parser.Convert;
import duke.storage.Storage;
import duke.order.Order;
import duke.order.OrderList;
Expand All @@ -12,7 +13,10 @@ public class FindOrderByDate extends OrderCommand {

private Date toView;

public FindOrderByDate(Date toView) {
public FindOrderByDate(String command) {
//expected to be "date xxxx"
String date = command.split(" ")[1];
Date toView = Convert.stringToDate(date);
this.toView = toView;
}

Expand Down
44 changes: 44 additions & 0 deletions src/main/java/duke/orderCommand/PostponeOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package duke.orderCommand;

import duke.command.Command;
import duke.exception.DukeException;
import duke.parser.Convert;
import duke.storage.Storage;
import duke.order.OrderList;
import duke.ui.Ui;

import java.util.Date;

public class PostponeOrder extends OrderCommand {

private int orderNb;
private String until;
private Date date;

/**
* The constructor method for snooze.
*
* @param orderNb order number
* @param until snooze until when
*/
public PostponeOrder(int orderNb, String until) {
this.orderNb = orderNb;
this.until = until;
this.date = Convert.stringToDate(until);
}

@Override
public void execute(OrderList orderList, Ui ui, Storage storage) throws DukeException {
if (orderNb < orderList.size() && orderNb >= 0) {
if (orderList.getOrder(orderNb).isDone()) {
throw new DukeException("Seems like you've already finished that order, no need to snooze it now");
}
orderList.changeOrderDate(orderNb, until);
ui.showChangedDate(Convert.getDateString(date, until),orderList.getOrder(orderNb).toString());
storage.changeContent(orderNb);
} else {
throw new DukeException("Enter a valid order number after snooze, between 1 and " + orderList.size());
}
}
}

161 changes: 0 additions & 161 deletions src/main/java/duke/orderCommand/StartNewOrder.java

This file was deleted.

11 changes: 6 additions & 5 deletions src/main/java/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ public static OrderCommand parse(String fullCommand) throws DukeException {
return new DoneOrder(splitted[1]);
case "cancel":
return new CancelOrder(splitted[1]);
case "cancel":
return new CancelOrder(splitted[1]);
case "cancel":
return new CancelOrder(splitted[1]);
case "":return;
case "postpone":
checkLength(splitted);
String[] getUntil = splitAndCheck(splitted[1], " /by ");
return new PostponeOrder(Integer.parseInt(getUntil[0]), getUntil[1]);
case "find":
return new FindOrderByDate(splitted[1]);
default:
throw new DukeException("I'm sorry, but I don't know what that means :-(");
}
Expand Down

0 comments on commit 61a3f68

Please sign in to comment.