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

Fix multiple issues #188

Merged
merged 3 commits into from
Apr 14, 2024
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
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_ROLE + "ROLE]... "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_METADATA + "METADATA]...\n"
+ "[" + PREFIX_METADATA + "METADATA]\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/seedu/address/logic/commands/ChargeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;

import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand All @@ -26,15 +28,18 @@
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Adds a certain amount to how much all matching CCA + optional role members owe. "
+ "Parameters: "
+ "[" + PREFIX_AMOUNT + "AMOUNT]...\n"
+ "[" + PREFIX_CCA + "AMOUNT] (more than one allowed)...\n"
+ "[" + PREFIX_ROLE + "AMOUNT] (more than one allowed)...\n"
+ PREFIX_AMOUNT + "AMOUNT "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_ROLE + "ROLE]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_AMOUNT + "10.00 "
+ PREFIX_CCA + "NUS Cycling "
+ PREFIX_ROLE + "friends";

public static final String MESSAGE_NO_AMOUNT = "An amount should be provided.";
public static final String MESSAGE_DO_NOTHING =
"Nobody was charged as nobody is in any of the following CCAs: [%s] "
+ "AND in any of the following roles: [%s]";
private final Amount amount;
private final CcaContainsKeywordPredicate ccas;

Expand Down Expand Up @@ -64,8 +69,16 @@
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> oldList = model.getFilteredPersonList().stream().collect(Collectors.toList());

Check warning on line 72 in src/main/java/seedu/address/logic/commands/ChargeCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ChargeCommand.java#L72

Added line #L72 was not covered by tests
model.updateFilteredPersonList(this.ccas);
List<Person> lastShownList = model.getFilteredPersonList();
if (lastShownList.isEmpty()) {
model.updateFilteredPersonList(oldList::contains);
Collector<CharSequence, ?, String> join = Collectors.joining(", ");
throw new CommandException(String.format(MESSAGE_DO_NOTHING,
ccas.getCcas().stream().map(c -> c.ccaName).collect(join),
ccas.getRoles().map(rs -> rs.stream().map(r -> r.roleName).collect(join)).orElse("")));

Check warning on line 80 in src/main/java/seedu/address/logic/commands/ChargeCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ChargeCommand.java#L76-L80

Added lines #L76 - L80 were not covered by tests
}

StringBuilder result = new StringBuilder();
for (Person personToOwe : lastShownList) {
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CCA;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -27,11 +26,13 @@
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes a CCA and all its associated members from your contacts. "
+ "Parameters: "
+ "[" + PREFIX_CCA + "CCA]...\n"
+ PREFIX_CCA + "CCA\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_CCA + "NUS Cycling ";

public static final String MESSAGE_NO_CCA = "A CCA should be provided.";
public static final String MESSAGE_NONEXISTANT_CCA = "No CCA was deleted because "
+ "the CCA `%s` does not exists.";
private final CcaContainsKeywordPredicate ccas;

/**
Expand All @@ -53,9 +54,21 @@
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

// Check if any CCA does not exists
List<Cca> ccalist = model.getAddressBook().getCcaList();
List<Cca> nonexistantCcas = this.ccas.getCcas().stream()

Check warning on line 60 in src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java#L59-L60

Added lines #L59 - L60 were not covered by tests
.filter(c1 -> !ccalist.stream().anyMatch(c1::isSameCcaName))
.collect(Collectors.toList());

Check warning on line 62 in src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java#L62

Added line #L62 was not covered by tests
if (!nonexistantCcas.isEmpty()) {
throw new CommandException(String.format(MESSAGE_NONEXISTANT_CCA,
nonexistantCcas.stream().map(c -> c.ccaName).collect(Collectors.joining(", "))));

Check warning on line 65 in src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java#L64-L65

Added lines #L64 - L65 were not covered by tests
}

model.updateFilteredPersonList(this.ccas);
StringBuilder result = new StringBuilder();
result.append(String.format("Deleting CCA(s) %s tags from all its members:\n", this.ccas));
result.append(String.format("Deleting CCA(s) %s tags from all its members:\n",
this.ccas.getCcas().stream().map(c -> c.ccaName).collect(Collectors.joining(", "))));

Check warning on line 71 in src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCcaCommand.java#L70-L71

Added lines #L70 - L71 were not covered by tests

// We have to essentially clone the list
// because as `model.setPerson` is called,
Expand All @@ -67,19 +80,12 @@
.collect(Collectors.toList());

// Delete their roles
ArrayList<Cca> removedCcas = new ArrayList<>();
affectedPeople
.forEach(affectedPerson -> {
Set<Cca> updatedCca = affectedPerson
.getCcas()
.stream()
.filter(c -> {
boolean isToDelete = ccas.contains(c);
if (isToDelete) {
removedCcas.add(c);
}
return !isToDelete;
})
.filter(c -> !ccas.contains(c))
.collect(Collectors.toSet());
model.setPerson(affectedPerson, affectedPerson.replaceCca(updatedCca));
result.append(String.format("Person affected: %s\n", affectedPerson.getName()));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class EditCommand extends Command {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_ROLE + "ROLE] "
+ "[" + PREFIX_CCA + "CCA] "
+ "[" + PREFIX_METADATA + "Meta-data]...\n"
+ "[" + PREFIX_ROLE + "ROLE]... "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_METADATA + "METADATA]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]\n\n"
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/seedu/address/logic/commands/FilterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CCA;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand All @@ -17,10 +19,14 @@ public class FilterCommand extends Command {

public static final String COMMAND_WORD = "filter";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filters a person by their CCA "
+ "(case-sensitive) and optionally their roles."
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Filters a person by their CCA "
+ "(case-sensitive) and optionally their roles. "
+ "Exact word matches are required. "
+ "Displays them as a list with index numbers.\n"
+ "Parameters: c/CCA c/[MORE CCAs]... r/ROLE /r[MORE ROLES]\n"
+ "Parameters: "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_ROLE + "ROLE]...\n"
+ "Example: " + COMMAND_WORD + " c/NUS Cycling r/Member";

public static final String MESSAGE_NOT_FILTER_CCA = "A CCA should be provided.";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/OweCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class OweCommand extends Command {
+ "by the index number used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_AMOUNT + "AMOUNT]...\n"
+ PREFIX_AMOUNT + "AMOUNT\n"
+ "Example: " + COMMAND_WORD + " 2 "
+ PREFIX_AMOUNT + "10.00 ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public AddCommand parse(String args) throws ParseException {
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_METADATA);
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ public ChargeCommand parse(String args) throws ParseException {
);
}

// Make sure all roles are not empty
if (argumentMultimap.getAllValues(PREFIX_ROLE).stream().anyMatch(String::isEmpty)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_ROLE_EMPTY)
+ "\n" + ChargeCommand.MESSAGE_USAGE);
}


Set<Cca> ccas = new HashSet<>(ParserUtil.parseCcas(argumentMultimap.getAllValues(PREFIX_CCA)));

Optional<Set<Role>> roles = argumentMultimap.getAllValues(PREFIX_ROLE).isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@
);
}

if (argumentMultimap.getAllValues(PREFIX_CCA).size() > 1) {
throw new ParseException(
String.format(
MESSAGE_INVALID_COMMAND_FORMAT, "Cannot delete more than one CCA."
)
);
}
argumentMultimap.verifyNoDuplicatePrefixesFor(PREFIX_CCA);

Check warning on line 41 in src/main/java/seedu/address/logic/parser/DeleteCcaCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteCcaCommandParser.java#L41

Added line #L41 was not covered by tests

Set<Cca> ccas = new HashSet<>(ParserUtil.parseCcas(argumentMultimap.getAllValues(PREFIX_CCA)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public EditCommand parse(String args) throws ParseException {
+ "\n" + EditCommand.MESSAGE_USAGE, pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(
PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_METADATA);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public OweCommand parse(String args) throws ParseException {
+ "\n" + OweCommand.MESSAGE_USAGE, pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_AMOUNT);

if (argMultimap.getValue(PREFIX_AMOUNT).isEmpty()) {
throw new ParseException(OweCommand.MESSAGE_NOT_OWE);
}
Expand Down
Loading