Skip to content

Commit

Permalink
Merge pull request #47 from IamRENCE/feedback-command
Browse files Browse the repository at this point in the history
v1.2 Feedback command
  • Loading branch information
DanKhoo committed Oct 24, 2018
2 parents 4acaab9 + 45d6493 commit 108d1e1
Show file tree
Hide file tree
Showing 34 changed files with 568 additions and 58 deletions.
19 changes: 5 additions & 14 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Feedback;
import seedu.address.model.person.Manager;
import seedu.address.model.person.Name;
import seedu.address.model.person.OtHour;
Expand Down Expand Up @@ -122,13 +123,15 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
OtHour updatedHours = editPersonDescriptor.getHours().orElse(personToEdit.getOtHours());
OtRate updatedRate = editPersonDescriptor.getRate().orElse(personToEdit.getOtRate());
PayDeductibles updatedDeductibles = editPersonDescriptor.getDeductibles().orElse(personToEdit.getDeductibles());
Rating updatedRating = editPersonDescriptor.getRating().orElse(personToEdit.getRating());
Rating updatedRating = personToEdit.getRating();
Department updatedDepartment = editPersonDescriptor.getDepartment().orElse(personToEdit.getDepartment());
Manager updatedManager = editPersonDescriptor.getManager().orElse(personToEdit.getManager());
Feedback updatedFeedback = personToEdit.getFeedback();
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRating, updatedDepartment,
updatedManager, updatedSalary, updatedHours, updatedRate, updatedDeductibles, updatedTags);
updatedManager, updatedSalary, updatedHours, updatedRate, updatedDeductibles, updatedFeedback,
updatedTags);
}

@Override
Expand Down Expand Up @@ -162,7 +165,6 @@ public static class EditPersonDescriptor {
private OtHour hours;
private OtRate rate;
private PayDeductibles deductibles;
private Rating rating;
private Department department;
private Manager manager;
private Set<Tag> tags;
Expand All @@ -182,7 +184,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setHours(toCopy.hours);
setRate(toCopy.rate);
setDeductibles(toCopy.deductibles);
setRating(toCopy.rating);
setDepartment(toCopy.department);
setManager(toCopy.manager);
setTags(toCopy.tags);
Expand Down Expand Up @@ -252,7 +253,6 @@ public Optional<PayDeductibles> getDeductibles() {
return Optional.ofNullable(deductibles);
}


public void setAddress(Address address) {
this.address = address;
}
Expand All @@ -261,14 +261,6 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setRating(Rating rating) {
this.rating = rating;
}

public Optional<Rating> getRating() {
return Optional.ofNullable(rating);
}

public void setDepartment(Department department) {
this.department = department;
}
Expand Down Expand Up @@ -325,7 +317,6 @@ && getSalary().equals(e.getSalary())
&& getHours().equals(e.getHours())
&& getRate().equals(e.getRate())
&& getDeductibles().equals(e.getDeductibles())
&& getRating().equals(e.getRating())
&& getDepartment().equals(e.getDepartment())
&& getManager().equals(e.getManager())
&& getTags().equals(e.getTags());
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/seedu/address/logic/commands/FeedbackCommand.java
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
}
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/RateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


/**
* Edits the details of an existing person in the address book.
* Edits the rating details of an existing person in the address book.
*/
public class RateCommand extends Command {

Expand Down Expand Up @@ -64,7 +64,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(),
personToEdit.getAddress(), rating, personToEdit.getDepartment(), personToEdit.getManager(),
personToEdit.getSalary(), personToEdit.getOtHours(), personToEdit.getOtRate(),
personToEdit.getDeductibles(), personToEdit.getTags());
personToEdit.getDeductibles(), personToEdit.getFeedback(), personToEdit.getTags());

model.updatePerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Feedback;
import seedu.address.model.person.Manager;
import seedu.address.model.person.Name;
import seedu.address.model.person.OtHour;
Expand Down Expand Up @@ -115,10 +116,11 @@ public AddCommand parse(String args) throws ParseException {
PayDeductibles deductibles = PayDeductibles.DEFAULT_INITIAL_DEDUCTIBLES;
Department department = ParserUtil.parseDepartment(argMultimap.getValue(PREFIX_DEPARTMENT).get());
Manager manager = ParserUtil.parseManager(argMultimap.getValue(PREFIX_MANAGER).get());
Feedback feedback = Feedback.DEFAULT_INITIAL_FEEDBACK;
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, rating, department, manager,
salary, hours, rate, deductibles, tagList);
salary, hours, rate, deductibles, feedback, tagList);

return new AddCommand(person);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FeedbackCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
Expand Down Expand Up @@ -88,6 +89,9 @@ public Command parseCommand(String userInput) throws ParseException {
case RateCommand.COMMAND_WORD:
return new RateCommandParser().parse(arguments);

case FeedbackCommand.COMMAND_WORD:
return new FeedbackCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class CliSyntax {
public static final Prefix PREFIX_OTHOUR = new Prefix("oth/");
public static final Prefix PREFIX_OTRATE = new Prefix("otr/");
public static final Prefix PREFIX_DEDUCTIBLES = new Prefix("de/");
public static final Prefix PREFIX_FEEDBACK = new Prefix("fb/");


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_OTHOUR;
import static seedu.address.logic.parser.CliSyntax.PREFIX_OTRATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_RATING;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -34,13 +33,15 @@ public class EditCommandParser implements Parser<EditCommand> {
/**
* Parses the given {@code String} of arguments in the context of the EditCommand
* and returns an EditCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public EditCommand parse(String args) throws ParseException {

requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_RATING, PREFIX_DEPARTMENT, PREFIX_MANAGER, PREFIX_SALARY, PREFIX_OTHOUR,
PREFIX_DEPARTMENT, PREFIX_MANAGER, PREFIX_SALARY, PREFIX_OTHOUR,
PREFIX_OTRATE, PREFIX_DEDUCTIBLES, PREFIX_TAG);

Index index;
Expand Down Expand Up @@ -77,9 +78,6 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setDeductibles(ParserUtil.parseDeductibles(argMultimap
.getValue(PREFIX_DEDUCTIBLES).get()));
}
if (argMultimap.getValue(PREFIX_RATING).isPresent()) {
editPersonDescriptor.setRating(ParserUtil.parseRating(argMultimap.getValue(PREFIX_RATING).get()));
}
if (argMultimap.getValue(PREFIX_DEPARTMENT).isPresent()) {
editPersonDescriptor.setDepartment(ParserUtil.parseDepartment(argMultimap.getValue(PREFIX_DEPARTMENT)
.get()));
Expand Down
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();
}
}
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Feedback;
import seedu.address.model.person.Manager;
import seedu.address.model.person.Name;
import seedu.address.model.person.OtHour;
Expand Down Expand Up @@ -200,6 +201,21 @@ public static Manager parseManager(String manager) throws ParseException {
return new Manager(trimmedManager);
}

/**
* Parses a {@code String feedback} into an {@code Feedback}
* Leading and trailing whitespaces wil be trimmed.
*
* @throws ParseException if the given {@code feedback} is invalid.
*/
public static Feedback parseFeedback(String feedback) throws ParseException {
requireNonNull(feedback);
String trimmedFeedback = feedback.trim();
if (!Feedback.isValidFeedback(trimmedFeedback)) {
throw new ParseException(Feedback.MESSAGE_CONSTRAINTS);
}
return new Feedback(trimmedFeedback);
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public class RateCommandParser implements Parser<RateCommand> {

/**
* Parses the given {@code String} of arguments in the context of the DeleteCommand
* and returns an DeleteCommand object for execution.
* Parses the given {@code String} of arguments in the context of the RateCommand
* and returns an RateCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public RateCommand parse(String args) throws ParseException {
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/seedu/address/model/person/Feedback.java
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();
}

}
Loading

0 comments on commit 108d1e1

Please sign in to comment.