Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fulfill order to use UUID in place of index #235

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the UG


```
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
Loading