Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Edit List employee #26

Merged
merged 7 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ public static String format(Person person) {
.append(person.getEmail())
.append("; Address: ")
.append(person.getAddress())
.append("; Tags: ");
person.getTags().forEach(builder::append);
.append("; Salary: ")
.append(person.getSalary())
.append("; Claim budget: ")
.append(person.getClaimBudget())
.append("; Department: ")
.append(person.getDepartment())
.append("; DOB: ")
.append(person.getDob());
return builder.toString();
}

Expand Down
20 changes: 14 additions & 6 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand All @@ -20,22 +23,27 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an employee to the employee list.\n"
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ PREFIX_SALARY + "SALARY "
+ PREFIX_CLAIM_BUDGET + "CLAIM BUDGET "
+ PREFIX_DEPARTMENT + "DEPARTMENT "
+ PREFIX_DOB + "BIRTHDATE (YYYY-MM-DD)\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_SALARY + "7000 "
+ PREFIX_CLAIM_BUDGET + "1500 "
+ PREFIX_DEPARTMENT + "Engineering "
+ PREFIX_DOB + "1999-07-23";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_SUCCESS = "New employee added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";

private final Person toAdd;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class DeleteCommand extends Command {
public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ ": Deletes the employee identified by the index number used in the displayed employee list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted employee: %1$s";

private final Index targetIndex;

Expand Down
94 changes: 65 additions & 29 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
Expand All @@ -22,11 +22,13 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Money;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;

/**
* Edits the details of an existing person in the address book.
Expand All @@ -35,20 +37,23 @@ public class EditCommand extends Command {

public static final String COMMAND_WORD = "edit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified "
+ "by the index number used in the displayed person list. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the employee identified "
+ "by the index number used in the displayed employee list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_SALARY + "SALARY] "
+ "[" + PREFIX_CLAIM_BUDGET + "CLAIM BUDGET] "
+ "[" + PREFIX_DEPARTMENT + "DEPARTMENT] "
+ "[" + PREFIX_DOB + "BIRTHDATE (YYYY-MM-DD)]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited employee: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";

Expand Down Expand Up @@ -99,9 +104,13 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Money updatedSalary = editPersonDescriptor.getSalary().orElse(personToEdit.getSalary());
Money updatedClaimBudget = editPersonDescriptor.getClaimBudget().orElse(personToEdit.getClaimBudget());
Department updatedDepartment = editPersonDescriptor.getDepartment().orElse(personToEdit.getDepartment());
Birthday updateDob = editPersonDescriptor.getDob().orElse(personToEdit.getDob());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
updatedSalary, updatedClaimBudget, updatedDepartment, updateDob);
}

@Override
Expand Down Expand Up @@ -137,7 +146,10 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private Set<Tag> tags;
private Money salary;
private Money claimBudget;
private Department department;
private Birthday dob;

public EditPersonDescriptor() {}

Expand All @@ -150,14 +162,17 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setSalary(toCopy.salary);
setClaimBudget(toCopy.claimBudget);
setDepartment(toCopy.department);
setDob(toCopy.dob);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, salary, claimBudget, department, dob);
}

public void setName(Name name) {
Expand Down Expand Up @@ -192,21 +207,36 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
*/
public void setTags(Set<Tag> tags) {
this.tags = (tags != null) ? new HashSet<>(tags) : null;
public void setSalary(Money salary) {
this.salary = salary;
}

/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
*/
public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
public Optional<Money> getSalary() {
return Optional.ofNullable(salary);
}

public void setClaimBudget(Money claimBudget) {
this.claimBudget = claimBudget;
}

public Optional<Money> getClaimBudget() {
return Optional.ofNullable(claimBudget);
}

public void setDepartment(Department department) {
this.department = department;
}

public Optional<Department> getDepartment() {
return Optional.ofNullable(department);
}

public void setDob(Birthday dob) {
this.dob = dob;
}

public Optional<Birthday> getDob() {
return Optional.ofNullable(dob);
}

@Override
Expand All @@ -225,7 +255,10 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
&& Objects.equals(salary, otherEditPersonDescriptor.salary)
&& Objects.equals(claimBudget, otherEditPersonDescriptor.claimBudget)
&& Objects.equals(department, otherEditPersonDescriptor.department)
&& Objects.equals(dob, otherEditPersonDescriptor.dob);
}

@Override
Expand All @@ -235,7 +268,10 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("tags", tags)
.add("salary", salary)
.add("claimBudget", claimBudget)
.add("department", department)
.add("dob", dob)
.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_SUCCESS = "Listed all persons";
public static final String MESSAGE_SUCCESS = "Listed all employees";


@Override
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY;

import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Department;
import seedu.address.model.person.Email;
import seedu.address.model.person.Money;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;

/**
* Parses input arguments and creates a new AddCommand object
Expand All @@ -31,21 +35,27 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_SALARY, PREFIX_CLAIM_BUDGET, PREFIX_DEPARTMENT, PREFIX_DOB);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_SALARY, PREFIX_CLAIM_BUDGET, PREFIX_DEPARTMENT, PREFIX_DOB)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_SALARY, PREFIX_CLAIM_BUDGET, PREFIX_DEPARTMENT, PREFIX_DOB);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Money salary = ParserUtil.parseMoney(argMultimap.getValue(PREFIX_SALARY).get());
Money claimBudget = ParserUtil.parseMoney(argMultimap.getValue(PREFIX_CLAIM_BUDGET).get());
Department department = ParserUtil.parseDepartment(argMultimap.getValue(PREFIX_DEPARTMENT).get());
Birthday dob = ParserUtil.parseDob(argMultimap.getValue(PREFIX_DOB).get());

Person person = new Person(name, phone, email, address, tagList);
Person person = new Person(name, phone, email, address, salary, claimBudget, department, dob);

return new AddCommand(person);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class CliSyntax {
public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_SALARY = new Prefix("s/");
public static final Prefix PREFIX_CLAIM_BUDGET = new Prefix("b/");
public static final Prefix PREFIX_DEPARTMENT = new Prefix("d/");
public static final Prefix PREFIX_DOB = new Prefix("dob/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

}
Loading
Loading