Skip to content

Commit

Permalink
Implement DeleteClient
Browse files Browse the repository at this point in the history
Added classes DeleteClientCommand and DeleteClientCommandParser
  • Loading branch information
Mahidharah committed Nov 1, 2023
2 parents 1fdca40 + 4c69557 commit bc4c03e
Show file tree
Hide file tree
Showing 72 changed files with 1,382 additions and 442 deletions.
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ public static boolean containsWordIgnoreCase(String sentence, String word) {
.anyMatch(preppedWord::equalsIgnoreCase);
}

/**
* Returns true if the {@code sentence} contains the {@code word} as a partial word match.
* Ignores case, and it matches the word even if it's only a part of a larger word.
* <br>examples:<pre>
* containsPartialWordIgnoreCase("ABc def", "abc") == true
* containsPartialWordIgnoreCase("ABc def", "DEF") == true
* containsPartialWordIgnoreCase("ABc def", "AB") == true
* </pre>
* @param sentence cannot be null
* @param word cannot be null, cannot be empty
*/
public static boolean containsPartialWordIgnoreCase(String sentence, String word) {
requireNonNull(sentence);
requireNonNull(word);

String preppedWord = word.trim();
checkArgument(!preppedWord.isEmpty(), "Word parameter cannot be empty");

String preppedSentence = sentence;
String[] wordsInPreppedSentence = preppedSentence.split("\\s+");

return Arrays.stream(wordsInPreppedSentence)
.anyMatch(wordInSentence -> wordInSentence.toLowerCase().contains(preppedWord.toLowerCase()));
}

/**
* Returns a detailed message of the t, including the stack trace.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.LockCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -41,6 +42,7 @@ public LogicManager(Model model, Storage storage) {
this.model = model;
this.storage = storage;
addressBookParser = new AddressBookParser();
new LockCommand().execute(model);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class Messages {
public static final String MESSAGE_INVALID_DEVELOPER_DISPLAYED_INDEX = "The developer index provided is invalid!";
public static final String MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX = "The client index provided is invalid!";
public static final String MESSAGE_INVALID_PROJECT_DISPLAYED_INDEX = "The project index provided is invalid!";
public static final String MESSAGE_INAPPLICABLE_PREFIX_USED = "You tried to edit an inapplicable field! Please check " +
"the prefixes used and try again. \n%1$s";
public static final String MESSAGE_INAPPLICABLE_PREFIX_USED = "You tried to edit an inapplicable field! "
+ "Please check the prefixes used and try again. \n%1$s";
public static final String MESSAGE_NONEXISTENT_PROJECT = "There is no existing Project with the name: %1$s!";
public static String getMessageDevelopersListedOverview(int count) {
return count == 1
Expand Down Expand Up @@ -101,7 +101,7 @@ public static Object format(seedu.address.model.project.Project project) {
.append(";\nDescription: ")
.append(project.getProjectDescription())
.append(";\nDeadlines:\n");
project.getProjectDeadlines().forEach(builder::append);
project.getProjectDeadlines().forEach(t -> builder.append(t.getStringRepresentation()));
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package seedu.address.logic.commands;

import seedu.address.logic.parser.AddressBookParser;
import seedu.address.model.Model;
import seedu.address.model.Password;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.*;

public class ChangePasswordCommand extends Command {
public static final String COMMAND_WORD = "change-password";
public static final Object MESSAGE_USAGE = COMMAND_WORD + ": Please change password to correct format\n"
+ Password.MESSAGE_CONSTRAINTS + "\n"
+ "Example: " + COMMAND_WORD + " pw/Password123! npw/NewPass987!";
private String currentPw;
private String newPw;

public ChangePasswordCommand(String currentPw, String newPw) {
this.currentPw = currentPw;
this.newPw = newPw;
}

@Override
public CommandResult execute(Model model) {
assert model != null : "Model cannot be null";
requireNonNull(model);
String result = Password.changePassword(currentPw,newPw);
return new CommandResult(result,TabIndex.Developer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class ClearCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
return new CommandResult(MESSAGE_SUCCESS,TabIndex.Developer);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true,TabIndex.Developer);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, TabIndex.Developer);
}

}
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/logic/commands/LockCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.address.logic.commands;

import seedu.address.logic.parser.AddressBookParser;
import seedu.address.model.Model;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.*;

public class LockCommand extends Command{
public static final String COMMAND_WORD = "lock";

public static final String MESSAGE_SUCCESS = "Locked all data";


@Override
public CommandResult execute(Model model) {
assert model != null : "Model cannot be null";
requireNonNull(model);
model.updateFilteredClientList(PREDICATE_SHOW_NO_CLIENT);
model.updateFilteredDeveloperList(PREDICATE_SHOW_NO_DEVELOPER);
model.updateFilteredProjectList(PREDICATE_SHOW_NO_PROJECT);
AddressBookParser.lock();
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

public class RedoCommand extends Command {
public static final String COMMAND_WORD = "redo";
public static final String MESSAGE_SUCCESS = "Redo successful!";

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.redoAddressBook(model);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/TabIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public enum TabIndex {
Developer,
Client,
Project
developers, Project
}
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;

public class UndoCommand extends Command {
public static final String COMMAND_WORD = "undo";
public static final String MESSAGE_SUCCESS = "Undo successful!";
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.undoAddressBook(model);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
36 changes: 36 additions & 0 deletions src/main/java/seedu/address/logic/commands/UnlockCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.commands;

import seedu.address.logic.parser.AddressBookParser;
import seedu.address.model.Model;
import seedu.address.model.Password;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.*;

public class UnlockCommand extends Command {
public static final String COMMAND_WORD = "unlock";

public static final String MESSAGE_SUCCESS = "Unlocked all data";
public static final String MESSAGE_FAILURE = "Incorrect Password!\n";
public static final Object MESSAGE_USAGE = COMMAND_WORD + ": Please unlock using correct format\n"
+ "Example: " + COMMAND_WORD + " pw/Password123!";
private String input;

public UnlockCommand(String input) {
this.input = input;
}

@Override
public CommandResult execute(Model model) {
assert model != null : "Model cannot be null";
requireNonNull(model);
if (Password.verifyPassword(input)) {
model.updateFilteredClientList(PREDICATE_SHOW_ALL_CLIENTS);
model.updateFilteredDeveloperList(PREDICATE_SHOW_ALL_DEVELOPERS);
model.updateFilteredProjectList(PREDICATE_SHOW_ALL_PROJECTS);
AddressBookParser.unlock();
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
return new CommandResult(String.format(MESSAGE_FAILURE,Password.MESSAGE_CONSTRAINTS),TabIndex.Developer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addClient(toAdd);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)), TabIndex.Client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addDeveloper(toAdd);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)), TabIndex.Developer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addProject(toAdd);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)), TabIndex.Project);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public CommandResult execute(Model model) throws CommandException {

Developer developerToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteDeveloper(developerToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_DEVELOPER_SUCCESS, Messages.format(developerToDelete)), TabIndex.Developer);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_DELETE_DEVELOPER_SUCCESS, Messages.format(developerToDelete)),TabIndex.Developer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setClient(clientToEdit, editedClient);
model.updateFilteredClientList(Model.PREDICATE_SHOW_ALL_CLIENTS);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_EDIT_CLIENT_SUCCESS, Messages.format(editedClient)), TabIndex.Client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setDeveloper(developerToEdit, editedDeveloper);
model.updateFilteredDeveloperList(Model.PREDICATE_SHOW_ALL_DEVELOPERS);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_EDIT_DEVELOPER_SUCCESS, Messages.format(editedDeveloper)), TabIndex.Developer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setProject(projectToEdit, editedProject);
model.updateFilteredProjectList(Model.PREDICATE_SHOW_ALL_PROJECTS);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_EDIT_PROJECT_SUCCESS, Messages.format(editedProject)), TabIndex.Project);
}

Expand Down
Loading

0 comments on commit bc4c03e

Please sign in to comment.