forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update branch with addorder function
- Loading branch information
Showing
27 changed files
with
922 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,27 @@ Examples: | |
* `find testing123 n/John` returns an error message as there should not be | ||
prefixes before the first 'FIELD' and 'KEYWORD' pair | ||
|
||
### Adding an order : `addorder` | ||
|
||
Adds an order to a supplier. | ||
|
||
Format: `addorder INDEX d/DATE r/REMARK` | ||
|
||
* Adds an order to the supplier at the specified `INDEX`. The index refers to the index number shown in the displayed supplier list. The index **must be a positive integer, starting from 1** (1, 2, 3, …) | ||
* The date must be in the format `YYYY-MM-DD`. For example, `2020-12-31`. | ||
|
||
<box type="tip" seamless> | ||
|
||
**Note:** A person can have any number of orders (including 0) | ||
</box> | ||
|
||
Examples: | ||
* `addorder 1 d/2020-01-01 r/100 chicken wings` | ||
* `addorder 2 r/ 100 chicken wings d/ 2020-12-31` | ||
* `addorder 3 d/2020-01-01 r/100 chicken wings` | ||
* `addorder d/2020-01-01 r/100 chicken wings` returns an error as the index is not specified | ||
* `addorder r/` or `addorder d/` or `addorder r/ d/` returns an error message as the 'KEYWORD' field cannot be empty | ||
|
||
### Deleting a person : `delete` | ||
|
||
Deletes the specified person from the address book. | ||
|
@@ -253,13 +274,14 @@ _Details coming soon ..._ | |
|
||
## Command summary | ||
|
||
Action | Format, Examples | ||
-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
**Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 t/friend t/colleague` | ||
**Clear** | `clear` | ||
**Delete** | `delete INDEX`<br> e.g., `delete 3` | ||
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
| Action | Format, Examples | | ||
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| **Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 t/friend t/colleague` | | ||
| **Clear** | `clear` | | ||
| **Delete** | `delete INDEX`<br> e.g., `delete 3` | | ||
| **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | | ||
| **Find** | `find KEYWORD/ [KEYWORD]`<br> e.g., `find n/ James n/ T t/ friend t/ rich` | | ||
| **Add Order** | `addorder INDEX d/DATE r/REMARK`<br> e.g., `addorder 1 d/ 2020-01-01 r/ 100 chicken wings` | | ||
**Add Favourite** | `addfav [i/INDICES]` | ||
**Find** | `find KEYWORD/ [KEYWORD]`<br> e.g., `find n/ James n/ T t/ friend t/ rich` | ||
**List** | `list` | ||
**Help** | `help` | ||
| **List** | `list` | | ||
| **Help** | `help` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/seedu/address/logic/commands/AddOrderCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.order.Date; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Lists all persons in the address book to the user. | ||
*/ | ||
public class AddOrderCommand extends Command { | ||
public static final String COMMAND_WORD = "addorder"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New order added: %1$s"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Adds an order to the person identified " | ||
+ "by the index number used in the last person listing.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "d/ [DATE] r/ [REMARK] \n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "d/ 2024-01-01 r/ 100 chicken wings."; | ||
|
||
private final Index index; | ||
private final Date arrivalDate; | ||
private final String remark; | ||
|
||
/** | ||
* Creates an AddOrderCommand to add the specified {@code Person} | ||
*/ | ||
public AddOrderCommand(Index index, Date arrivalDate, String remark) { | ||
requireNonNull(index); | ||
requireNonNull(arrivalDate); | ||
requireNonNull(remark); | ||
|
||
this.index = index; | ||
this.arrivalDate = arrivalDate; | ||
this.remark = remark; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person person = lastShownList.get(index.getZeroBased()); | ||
|
||
// TODO | ||
person.addOrder(this.arrivalDate, this.remark); | ||
|
||
model.setPerson(person, person); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(person))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddOrderCommand)) { | ||
return false; | ||
} | ||
|
||
AddOrderCommand otherAddOrderCommand = (AddOrderCommand) other; | ||
return index.equals(otherAddOrderCommand.index) | ||
&& arrivalDate.equals(otherAddOrderCommand.arrivalDate) | ||
&& remark.equals(otherAddOrderCommand.remark); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("index", index) | ||
.add("arrivalDate", arrivalDate) | ||
.add("remark", remark) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/seedu/address/logic/parser/AddOrderCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AddOrderCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.order.Date; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddOrderCommand object | ||
*/ | ||
public class AddOrderCommandParser implements Parser<AddOrderCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddOrderCommand | ||
* and returns an AddOrderCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddOrderCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
|
||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DATE, PREFIX_REMARK); | ||
|
||
if (!argMultimap.arePrefixesPresent(PREFIX_DATE, PREFIX_REMARK)) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddOrderCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddOrderCommand.MESSAGE_USAGE), pe); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_DATE, PREFIX_REMARK); | ||
|
||
Date arrivalDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()); | ||
|
||
String remark = argMultimap.getValue(PREFIX_REMARK).get(); | ||
|
||
return new AddOrderCommand(index, arrivalDate, remark); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package seedu.address.model.order; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Represents a date of an order in the address book. | ||
*/ | ||
public class Date { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = "Date format should be YYYY-MM-DD, and it should not be blank"; | ||
|
||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
||
public final LocalDate date; | ||
|
||
/** | ||
* Constructs an {@code Date}. | ||
* | ||
* @param date a valid date string. | ||
*/ | ||
public Date(String date) { | ||
requireNonNull(date); | ||
checkArgument(isValidDate(date), MESSAGE_CONSTRAINTS); | ||
this.date = LocalDate.parse(date, DATE_TIME_FORMATTER); | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid date. | ||
*/ | ||
public static boolean isValidDate(String test) { | ||
try { | ||
LocalDate.parse(test, DATE_TIME_FORMATTER); | ||
return true; | ||
} catch (DateTimeParseException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return date.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof Date)) { | ||
return false; | ||
} | ||
|
||
Date otherDate = (Date) other; | ||
return date.equals(otherDate.date); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return date.hashCode(); | ||
} | ||
|
||
} |
Oops, something went wrong.