Skip to content

Commit

Permalink
Merge pull request #51 from SoilingRogue/branch-SwitchParser
Browse files Browse the repository at this point in the history
Order command implementation
  • Loading branch information
MackyMaguire authored Oct 14, 2019
2 parents eaafe65 + a6b074d commit fb6141c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public class Messages {
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_SWITCH_CONTEXT = "The context to switch to is invalid";
public static final String MESSAGE_ALREADY_IN_CONTEXT = "Already in %1$d context!";

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
package seedu.deliverymans.logic.commands.customer;

import static java.util.Objects.requireNonNull;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_CUSTOMER;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_DELIVERYMAN;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_ORDER;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_RESTAURANT;

import seedu.deliverymans.logic.commands.Command;
import seedu.deliverymans.logic.commands.CommandResult;
import seedu.deliverymans.logic.commands.exceptions.CommandException;
import seedu.deliverymans.model.Model;
import seedu.deliverymans.model.order.Order;

/**
* (to be added)
* Order command
*/
public class OrderCommand extends Command {
public static final String COMMAND_WORD = "order";

public static final String MESSAGE_ADD_SUCCESS = "Added order: %1$s";

public static final String MESSAGE_ADD_ORDER_USAGE = COMMAND_WORD
+ ": Adds an order to the manager. "
+ "Parameters: "
+ PREFIX_ORDER + "ORDER "
+ "[" + PREFIX_CUSTOMER + "CUSTOMER]\n"
+ "[" + PREFIX_RESTAURANT + "RESTAURANT]\n"
+ "[" + PREFIX_DELIVERYMAN + "DELIVERYMAN]\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_CUSTOMER + "Sam "
+ PREFIX_RESTAURANT + "KFC "
+ PREFIX_DELIVERYMAN + "Deliveryman #1337";

private final Order toAdd;

public OrderCommand(Order toAdd) {
requireNonNull(toAdd);
this.toAdd = toAdd;
}

@Override
public CommandResult execute(Model model) throws CommandException {
return null;
model.addOrder(toAdd);
return new CommandResult(String.format(MESSAGE_ADD_SUCCESS, toAdd));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof OrderCommand // instanceof handles nulls
&& toAdd.equals(((OrderCommand) other).toAdd));
}
}
13 changes: 12 additions & 1 deletion src/main/java/seedu/deliverymans/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ public class CliSyntax {
public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");
public static final Prefix PREFIX_REMARK = new Prefix("rr/");
public static final Prefix PREFIX_CUSTOMER = new Prefix("c/");
public static final Prefix PREFIX_DELIVERYMAN = new Prefix("d/");
public static final Prefix PREFIX_RESTAURANT = new Prefix("r/");

// Prefix for universal commands


// Prefix for customer commands
public static final Prefix PREFIX_ORDER = new Prefix("o/");

// Prefix for deliveryman commands

// Prefix for restaurant commands
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package seedu.deliverymans.logic.parser.customer;

import static java.util.Objects.requireNonNull;
import static seedu.deliverymans.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.deliverymans.logic.commands.customer.OrderCommand.MESSAGE_ADD_ORDER_USAGE;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_CUSTOMER;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_DELIVERYMAN;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_ORDER;
import static seedu.deliverymans.logic.parser.CliSyntax.PREFIX_RESTAURANT;

import seedu.deliverymans.logic.commands.customer.OrderCommand;
import seedu.deliverymans.logic.parser.ArgumentMultimap;
import seedu.deliverymans.logic.parser.ArgumentTokenizer;
import seedu.deliverymans.logic.parser.Parser;
import seedu.deliverymans.logic.parser.exceptions.ParseException;
import seedu.deliverymans.model.order.Order;

/**
* Parses input arguments and creates a new {@code OrderCommand} object
Expand All @@ -20,14 +26,26 @@ public class OrderCommandParser implements Parser<OrderCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public OrderCommand parse(String args) throws ParseException {
String orderName;
String customer;
String restaurant;
String deliveryman;

requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_ORDER);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_ORDER, PREFIX_CUSTOMER,
PREFIX_RESTAURANT, PREFIX_DELIVERYMAN);

try {
orderName = argMultimap.getValue(PREFIX_ORDER).orElse("");
customer = argMultimap.getValue(PREFIX_CUSTOMER).orElseThrow(() -> new Exception());
restaurant = argMultimap.getValue(PREFIX_RESTAURANT).orElseThrow(() -> new Exception());
deliveryman = argMultimap.getValue(PREFIX_DELIVERYMAN).orElseThrow(() -> new Exception());
} catch (Exception ive) {
throw new ParseException("");
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MESSAGE_ADD_ORDER_USAGE));
}

return new OrderCommand();
Order order = new Order(orderName, customer, restaurant, deliveryman);
return new OrderCommand(order);
}
}

0 comments on commit fb6141c

Please sign in to comment.