Skip to content

Commit

Permalink
Merge pull request #51 from LowTL/master
Browse files Browse the repository at this point in the history
Update command testing & delete exceptions
  • Loading branch information
LowTL committed Mar 25, 2024
2 parents 2da12d2 + d49ed14 commit 785bcee
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 19 deletions.
82 changes: 69 additions & 13 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,97 @@

## Introduction

{Give a product intro}
StockMaster is a platform aimed at helping SMEs track and organise their inventory.

## Quick Start

{Give steps to get started quickly}

1. Ensure that you have Java 11 or above installed.
1. Down the latest version of `Duke` from [here](http://link.to/duke).
2. Download the latest version of `StockMaster` from [here](http://link.to/duke).
3.

## Features

{Give detailed description of each feature}

### Adding a todo: `todo`
Adds a new item to the list of todo items.
### Adding an item: `add`
Adds a new item to the list of items.

Format: `todo n/TODO_NAME d/DEADLINE`
Format: `add ITEM_NAME qty/ITEM_QUANTITY [cat/CATEGORY]`

* The `DEADLINE` can be in a natural language format.
* The `TODO_NAME` cannot contain punctuation.
* `CATEGORY` is an optional field. If blank, it will default to `N/A`.

Example of usage:
```
add Apples qty/50
add Phone qty/5 cat/Electronics
```

`todo n/Write the rest of the User Guide d/next week`
### Deleting an item: `del`
Deletes the item from the list of items.

`todo n/Refactor the User Guide to remove passive voice d/13/04/2020`
Format: `del ITEM_NAME`

Example of usage:
```
del Apples
```

### Editing an item: `edit`
Edits the quantity of the item.

Format: `edit ITEM_NAME qty/NEW_QUANTITY`

Example of usage:
```
edit Apples qty/10
edit Phone qty/0
```

### Listing all items: `list`
Lists all stored items.

Format: `list [cat/CATEGORY]`

* `CATEGORY` is an optional field. By default, it will list all the stored items.

Example of usage:
```
list
list Electronics
```

### List all available commands: `help`
Lists all commands as per the command summary below.

Format: `help [c/COMMAND]`

* `COMMAND` is optional. Specifying the command will give a more comprehensive
description of the command.

Example of usage:
```
help
help c/add
```


### Closing the app: `exit`
Saves and closes the app safely.

Format: `exit`

## FAQ

**Q**: How do I transfer my data to another computer?

**A**: {your answer here}
**A**: Simply copy and paste the saved folder that is created upon launch of
the application.

## Command Summary

{Give a 'cheat sheet' of commands here}

* Add todo `todo n/TODO_NAME d/DEADLINE`
* Add new item: `add Apples qty/10 cat/Food`
* Delete an item: `delete Apples`
* List all items: `list`
* List all commands: `help`
6 changes: 4 additions & 2 deletions src/main/java/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command;

public abstract class Command {
import exceptions.CommandFormatException;

public abstract void execute();
public abstract class Command {

public abstract void execute() throws CommandFormatException;
}
5 changes: 4 additions & 1 deletion src/main/java/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package command;

import exceptions.CommandFormatException;
import item.Item;
import itemlist.Itemlist;
import parser.CommandType;
import storage.Storage;

public class DeleteCommand extends Command {
Expand All @@ -12,7 +14,7 @@ public DeleteCommand(String itemName) {
this.itemName = itemName;
}

public void execute() {
public void execute() throws CommandFormatException {
int index = -1;
for (Item item : Itemlist.getItems()) {
if (item.getItemName().toLowerCase().equals(itemName)) {
Expand All @@ -22,6 +24,7 @@ public void execute() {
}
if (index == -1) {
//throw exception;
throw new CommandFormatException(CommandType.DEL);
} else {
Itemlist.deleteItem(index);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import command.Command;
import command.ExitCommand;
import exceptions.CommandFormatException;
import parser.Parser;
import ui.TextUi;

Expand All @@ -17,17 +18,17 @@ public class Duke {
/**
* Main entry-point for the java.duke.Duke application.
*/
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, CommandFormatException {
new Duke().run();
}

public void run() throws IOException {
public void run() throws IOException, CommandFormatException {
ui.showWelcomeMessage("1.0", "./StockMasterData.txt");
this.normalOperation();
ui.showGoodByeMessage("./StockMasterData.txt");
}

private void normalOperation() throws IOException {
private void normalOperation() throws IOException, CommandFormatException {
String userInput;
do {
userInput = ui.getUserInput();
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/command/CommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package command;

import org.junit.jupiter.api.Test;

public class CommandTest {
private Command command;

@Test
public void command_invalidCommand_throwsError() {

}

}

0 comments on commit 785bcee

Please sign in to comment.