Skip to content

Commit

Permalink
Merge pull request #235 from cnivedit/bugfix/fulfillargs
Browse files Browse the repository at this point in the history
Update fulfill order to use UUID in place of index
  • Loading branch information
cnivedit authored Nov 11, 2024
2 parents 568340e + e99868e commit 2e13abc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ Completes an order by adding/removing items from the inventory.

The action taken depends on the order type (purchase/dispense) and the items in the order.

**Format**: `fulfill-order ORDER_ID`
**Format**: `fulfill-order ORDER_UUID`

**Sample Output**:

`> fulfill-order 1`
`> fulfill-order cec43f38-5c63-40b6-8964-00f8b4225c17`

```
Added the following item to the inventory:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/pill/command/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ private void showFulfillOrderHelp() {

System.out.println("fulfill-order: Processes and completes a pending order.");
if (verbose) {
System.out.println("Usage: fulfill-order <order-id>");
System.out.println(" <order-id> - The unique identifier of the order to fulfill");
System.out.println("Usage: fulfill-order <order-uuid>");
System.out.println(" <order-uuid> - The unique identifier of the order to fulfill");
System.out.println("\nExample:");
System.out.println(" fulfill-order 123e4567-e89b-12d3-a456-556642440000");
System.out.println("\nNote: This will create the necessary transactions and update inventory levels");
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/seedu/pill/util/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class Parser {
Expand Down Expand Up @@ -175,25 +176,31 @@ public void parseCommand(String input) {
/**
* Parses the arguments provided to create a {@link FulfillCommand} instance, which is used to fulfill an order.
*
* @param arguments The command input containing the order index to be fulfilled.
* @param arguments The command input containing the order UUID to be fulfilled.
* @return A {@link FulfillCommand} instance that contains the order and transaction manager.
* @throws PillException if the input contains too many arguments, is empty, cannot be parsed as a number,
* or if the specified order index is invalid.
* or if the specified order UUID is invalid.
*
*/
private FulfillCommand parseFulfillCommand(String arguments) throws PillException {
String[] commandArguments = arguments.split("\\s+");
if (commandArguments.length > 1) {
throw new PillException(ExceptionMessages.TOO_MANY_ARGUMENTS);
}
if (commandArguments.length == 0) {
if (commandArguments.length == 0 || arguments.isEmpty()) {
throw new PillException(ExceptionMessages.INVALID_FULFILL_COMMAND);
}
try {
Order order = transactionManager.getOrders().get(Integer.parseInt(commandArguments[0]) - 1);
List<Order> orders = transactionManager.getOrders();
String orderToFetch = commandArguments[0];
Order order = orders.stream()
.filter(orderInfo -> orderInfo.getId().toString().equals(orderToFetch))
.findFirst()
.orElse(null);
if (order == null) {
throw new PillException(ExceptionMessages.INVALID_ORDER);
}
return new FulfillCommand(order, transactionManager);
} catch (NumberFormatException e) {
throw new PillException(ExceptionMessages.INVALID_INDEX);
} catch (IndexOutOfBoundsException e) {
throw new PillException(ExceptionMessages.INVALID_ORDER);
}
Expand Down

0 comments on commit 2e13abc

Please sign in to comment.