forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2425S1#58 from 1st2GetThisName/branch…
…_add_vip Add partial VIP implementation
- Loading branch information
Showing
14 changed files
with
441 additions
and
13 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 |
---|---|---|
|
@@ -172,6 +172,21 @@ If your changes to the data file makes its format invalid, AddressBook will disc | |
Furthermore, certain edits can cause the AddressBook to behave in unexpected ways (e.g., if a value entered is outside the acceptable range). Therefore, edit the data file only if you are confident that you can update it correctly. | ||
</box> | ||
|
||
### Marking whether a person is a VIP : `vip` | ||
|
||
Marks the specified person from the address book as a VIP or removes said label. | ||
|
||
Format: `vip INDEX IS_VIP` | ||
|
||
* Affects the person at the specified `INDEX`. | ||
* The index refers to the index number shown in the displayed person list. | ||
* The index **must be a positive integer** 1, 2, 3, … | ||
* IS_VIP should either be `true` or `false`, corresponding to whether you intend to mark the target as a VIP or remove such a mark. | ||
|
||
Examples: | ||
* `list` followed by `vip 2 true` marks the 2nd person in the address book as a VIP. | ||
* `find Betsy` followed by `vip 1 false` removes VIP status from the 1st person in the results of the `find` command. | ||
|
||
### Archiving data files `[coming in v2.0]` | ||
|
||
_Details coming soon ..._ | ||
|
@@ -202,4 +217,5 @@ Action | Format, Examples | |
**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 [MORE_KEYWORDS]`<br> e.g., `find James Jake` | ||
**List** | `list` | ||
**Vip** | `vip INDEX IS_VIP`<br> e.g., `vip 3 true` | ||
**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
98 changes: 98 additions & 0 deletions
98
src/main/java/seedu/address/logic/commands/MarkVipCommand.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,98 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Comment; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Marks a person as a VIP or revokes that title. | ||
*/ | ||
public class MarkVipCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "vip"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Marks or unmarks the person identified by the index " | ||
+ "number used in the displayed person list as a VIP.\n" | ||
+ "Parameters: INDEX (must be a positive integer) IS_VIP (must be \"true\" or \"false\")\n" | ||
+ "Example: " + COMMAND_WORD + " 1 true"; | ||
|
||
public static final String MESSAGE_VIP_PERSON_SUCCESS = "Person marked as a VIP: %1$s"; | ||
public static final String MESSAGE_UNVIP_PERSON_SUCCESS = "VIP status removed from person: %1$s"; | ||
public static final String MESSAGE_VIP_PERSON_OBSOLETE = "Person already a VIP: %1$s"; | ||
public static final String MESSAGE_UNVIP_PERSON_OBSOLETE = "Person not a VIP: %1$s"; | ||
private final String messageSuccess; | ||
private final String messageObsolete; | ||
|
||
private final Index targetIndex; | ||
private final boolean newState; | ||
|
||
/** | ||
* Creates a MarkVipCommand to mark the specified {@code Person} as a VIP | ||
* @param targetIndex the index of the Person in the list | ||
* @param newState whether the Person should be labelled as a VIP when the operation is complete | ||
*/ | ||
public MarkVipCommand(Index targetIndex, boolean newState) { | ||
this.targetIndex = targetIndex; | ||
this.newState = newState; | ||
if (newState) { | ||
messageSuccess = MESSAGE_VIP_PERSON_SUCCESS; | ||
messageObsolete = MESSAGE_VIP_PERSON_OBSOLETE; | ||
} else { | ||
messageSuccess = MESSAGE_UNVIP_PERSON_SUCCESS; | ||
messageObsolete = MESSAGE_UNVIP_PERSON_OBSOLETE; | ||
} | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToMark = lastShownList.get(targetIndex.getZeroBased()); | ||
if (personToMark.isVip() == newState) { | ||
return new CommandResult(String.format(messageObsolete, Messages.format(personToMark))); | ||
} | ||
Name name = personToMark.getName(); | ||
Address address = personToMark.getAddress(); | ||
Email email = personToMark.getEmail(); | ||
Phone phone = personToMark.getPhone(); | ||
Comment comment = personToMark.getComment(); | ||
Set<Tag> tags = personToMark.getTags(); | ||
Person updatedPerson = new Person(name, phone, email, address, comment, tags, newState); | ||
model.setPerson(personToMark, updatedPerson); | ||
return new CommandResult(String.format(messageSuccess, Messages.format(personToMark))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MarkVipCommand)) { | ||
return false; | ||
} | ||
|
||
MarkVipCommand otherMarkVipCommand = (MarkVipCommand) other; | ||
return targetIndex.equals(otherMarkVipCommand.targetIndex) && newState == otherMarkVipCommand.newState; | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/seedu/address/logic/parser/MarkVipCommandParser.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,47 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.MarkVipCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new MarkVipCommand. | ||
*/ | ||
public class MarkVipCommandParser implements Parser<MarkVipCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the MarkVipCommand | ||
* and returns a MarkVipCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public MarkVipCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
String trimmedArgs = args.trim(); | ||
|
||
String[] splitArgs = trimmedArgs.split("\\s+"); | ||
|
||
if (splitArgs.length != 2) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkVipCommand.MESSAGE_USAGE)); | ||
} | ||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(splitArgs[0]); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkVipCommand.MESSAGE_USAGE), pe); | ||
} | ||
switch (splitArgs[1]) { | ||
case "true": | ||
return new MarkVipCommand(index, true); | ||
case "false": | ||
return new MarkVipCommand(index, false); | ||
default: | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkVipCommand.MESSAGE_USAGE)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.