forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #47 from IamRENCE/feedback-command
v1.2 Feedback command
- Loading branch information
Showing
34 changed files
with
568 additions
and
58 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
75 changes: 75 additions & 0 deletions
75
src/main/java/seedu/address/logic/commands/FeedbackCommand.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,75 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FEEDBACK; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Feedback; | ||
import seedu.address.model.person.Person; | ||
|
||
|
||
/** | ||
* Edits the feedback details of an existing person in the address book. | ||
*/ | ||
public class FeedbackCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "feedback"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Updates the feedback for the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Existing feedback will be overwritten by the input feedback.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_FEEDBACK + "FEEDBACK]\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "fb/5"; | ||
|
||
public static final String MESSAGE_FEEDBACK_PERSON_SUCCESS = "Feedback updated for Person: %1$s"; | ||
|
||
private final Index index; | ||
private final Feedback feedback; | ||
|
||
/** | ||
* @param index of the person in the filtered person list to edit | ||
*/ | ||
public FeedbackCommand(Index index, Feedback feedback) { | ||
requireNonNull(index); | ||
|
||
this.index = index; | ||
this.feedback = feedback; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
|
||
Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), | ||
personToEdit.getAddress(), personToEdit.getRating(), personToEdit.getDepartment(), | ||
personToEdit.getManager(), personToEdit.getSalary(), personToEdit.getOtHours(), | ||
personToEdit.getOtRate(), personToEdit.getDeductibles(), feedback, personToEdit.getTags()); | ||
|
||
model.updatePerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
model.commitAddressBook(); | ||
return new CommandResult(String.format(MESSAGE_FEEDBACK_PERSON_SUCCESS, editedPerson)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof FeedbackCommand // instanceof handles nulls | ||
&& index.equals(((FeedbackCommand) other).index)); // state check | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/seedu/address/logic/parser/FeedbackCommandParser.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,45 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FEEDBACK; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.FeedbackCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Feedback; | ||
|
||
/** | ||
* Parses input arguments and creates a new FeedbackCommand object | ||
*/ | ||
public class FeedbackCommandParser implements Parser<FeedbackCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the FeedbackCommand | ||
* and returns an FeedbackCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public FeedbackCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_FEEDBACK); | ||
|
||
Index index; | ||
String feedback; | ||
|
||
if (!isPrefixPresent(argMultimap, PREFIX_FEEDBACK) || argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FeedbackCommand.MESSAGE_USAGE)); | ||
} | ||
feedback = argMultimap.getValue(PREFIX_FEEDBACK).get(); | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
|
||
return new FeedbackCommand(index, new Feedback(feedback)); | ||
} | ||
|
||
/** | ||
* Returns true if prefix does not contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean isPrefixPresent(ArgumentMultimap argumentMultimap, Prefix prefix) { | ||
return argumentMultimap.getValue(prefix).isPresent(); | ||
} | ||
} |
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,58 @@ | ||
package seedu.address.model.person; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Person's feedback number in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidFeedback(String)} | ||
*/ | ||
public class Feedback { | ||
|
||
public static final Feedback DEFAULT_INITIAL_FEEDBACK = new Feedback("-NO FEEDBACK YET-"); | ||
public static final String MESSAGE_CONSTRAINTS = "Feedback can take any values, and it should not be blank"; | ||
|
||
/* | ||
* The first character of the address must not be a whitespace, | ||
* otherwise " " (a blank string) becomes a valid input. | ||
*/ | ||
public static final String VALIDATION_REGEX = "[^\\s].*"; | ||
public final String value; | ||
|
||
|
||
/** | ||
* Constructs a {@code Feedback}. | ||
* | ||
* @param feedback A valid feedback. | ||
*/ | ||
public Feedback(String feedback) { | ||
requireNonNull(feedback); | ||
checkArgument(isValidFeedback(feedback), MESSAGE_CONSTRAINTS); | ||
value = feedback; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid feedback number. | ||
*/ | ||
public static boolean isValidFeedback(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof Feedback // instanceof handles nulls | ||
&& value.equals(((Feedback) other).value)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
} |
Oops, something went wrong.