Skip to content

Commit

Permalink
Merge branch 'AY2324S1-CS2103T-T09-2:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahidharah authored Nov 2, 2023
2 parents c72e5da + ee2f347 commit 458c9ef
Show file tree
Hide file tree
Showing 34 changed files with 748 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.client.Client;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.client.Client;
import seedu.address.model.developer.Developer;
import seedu.address.storage.Storage;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ 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_INVALID_DEADLINE_DISPLAYED_INDEX = "The deadline 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_NONEXISTENT_PROJECT = "There is no existing Project with the name: %1$s!";
public static String getMessageDevelopersListedOverview(int count) {
return count == 1
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

public class RedoCommand extends Command {
public static final String COMMAND_WORD = "redo";
public static final String MESSAGE_SUCCESS = "Redo successful!";
public static final String MESSAGE_SUCCESS = "Redo successful! The change below has been redone:";

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
String previousCommand = model.getPreviousCommand();
TabIndex index = model.getPreviousTabIndex();
model.redoAddressBook(model);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
return new CommandResult(MESSAGE_SUCCESS + "\n" + previousCommand, index);
}
}
7 changes: 4 additions & 3 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
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!";
public static final String MESSAGE_SUCCESS = "Undo successful! The change below has been undone: ";
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.undoAddressBook(model);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
String previousCommand = model.getPreviousCommand();
TabIndex index = model.getPreviousTabIndex();
return new CommandResult(MESSAGE_SUCCESS + "\n" + previousCommand, index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_CLIENT);
}

String successMessage = String.format(MESSAGE_SUCCESS, Messages.format(toAdd));
TabIndex index = TabIndex.Client;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_DEVELOPER);
}

String successMessage = String.format(MESSAGE_SUCCESS, Messages.format(toAdd));
TabIndex index = TabIndex.Developer;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_PROJECT);
}

String successMessage = String.format(MESSAGE_SUCCESS, Messages.format(toAdd));
TabIndex index = TabIndex.Project;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package seedu.address.logic.commands.delete;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TabIndex;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.client.Client;

import java.util.List;

import static java.util.Objects.requireNonNull;

/**
* Deletes a developer identified using it's displayed index from the address book.
*/
public class DeleteClientCommand extends Command {

public static final String COMMAND_WORD = "delete-client";

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

public static final String MESSAGE_DELETE_CLIENT_SUCCESS = "Deleted Client: %1$s";

private final Index targetIndex;

public DeleteClientCommand (Index targetIndex) {
this.targetIndex = targetIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Client> lastShownList = model.getFilteredClientList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX);
}

Client clientToDelete = lastShownList.get(targetIndex.getZeroBased());
String successMessage = String.format(MESSAGE_DELETE_CLIENT_SUCCESS, Messages.format(clientToDelete));
TabIndex index = TabIndex.Client;

model.deleteClient(clientToDelete);
model.commitAddressBook(model, successMessage, index);
return new CommandResult(successMessage, index);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof DeleteClientCommand)) {
return false;
}

DeleteClientCommand otherDeleteClientCommand = (DeleteClientCommand) other;
return targetIndex.equals(otherDeleteClientCommand.targetIndex);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("targetIndex", targetIndex)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.delete;

import static java.util.Objects.requireNonNull;

Expand All @@ -7,6 +7,9 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TabIndex;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.developer.Developer;
Expand All @@ -27,7 +30,7 @@ public class DeleteDeveloperCommand extends Command {

private final Index targetIndex;

public DeleteDeveloperCommand (Index targetIndex) {
public DeleteDeveloperCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

Expand All @@ -41,9 +44,12 @@ public CommandResult execute(Model model) throws CommandException {
}

Developer developerToDelete = lastShownList.get(targetIndex.getZeroBased());
String successMessage = String.format(MESSAGE_DELETE_DEVELOPER_SUCCESS, Messages.format(developerToDelete));
TabIndex index = TabIndex.Developer;

model.deleteDeveloper(developerToDelete);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_DELETE_DEVELOPER_SUCCESS, Messages.format(developerToDelete)),TabIndex.Developer);
model.commitAddressBook(model, successMessage, index);
return new CommandResult(successMessage, index);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_CLIENT);
}

String successMessage = String.format(MESSAGE_EDIT_CLIENT_SUCCESS, Messages.format(editedClient));
TabIndex index = TabIndex.Client;

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);
model.commitAddressBook(model, successMessage, index);
return new CommandResult(successMessage, index);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_DEVELOPER);
}

String successMessage = String.format(MESSAGE_EDIT_DEVELOPER_SUCCESS, Messages.format(editedDeveloper));
TabIndex index = TabIndex.Developer;

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);
model.commitAddressBook(model, successMessage, index);
return new CommandResult(successMessage, index);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -72,7 +73,7 @@ static seedu.address.model.project.Project createEditedProject(seedu.address.mod
Name name = projectToEdit.getProjectName();
Description updatedDescription = editProjectDescriptor.getDescription()
.orElse(projectToEdit.getProjectDescription());
Set<Deadline> updatedDeadlines = editProjectDescriptor.getDeadlines().orElse(projectToEdit.getProjectDeadlines());
List<Deadline> updatedDeadlines = editProjectDescriptor.getDeadlines().orElse(projectToEdit.getProjectDeadlines());

return new seedu.address.model.project.Project(name, updatedDescription, updatedDeadlines);
}
Expand All @@ -92,10 +93,13 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_PROJECT);
}

String successMessage = String.format(MESSAGE_EDIT_PROJECT_SUCCESS, Messages.format(editedProject));
TabIndex index = TabIndex.developers;

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);
model.commitAddressBook(model, successMessage, index);
return new CommandResult(successMessage, index);
}


Expand Down Expand Up @@ -129,7 +133,7 @@ public String toString() {
*/
public static class EditProjectDescriptor {
private Description desc;
private Set<Deadline> deadlines;
private List<Deadline> deadlines;

public EditProjectDescriptor() {}

Expand Down Expand Up @@ -158,12 +162,12 @@ public Optional<Description> getDescription() {
return Optional.ofNullable(desc);
}

public void setDeadlines(Set<Deadline> deadlines) {
this.deadlines = (deadlines != null) ? new HashSet<>(deadlines) : null;
public void setDeadlines(List<Deadline> deadlines) {
this.deadlines = (deadlines != null) ? new ArrayList<>(deadlines) : null;
}

public Optional<Set<Deadline>> getDeadlines() {
return (deadlines != null) ? Optional.of(Collections.unmodifiableSet(deadlines)) : Optional.empty();
public Optional<List<Deadline>> getDeadlines() {
return (deadlines != null) ? Optional.of(Collections.unmodifiableList(deadlines)) : Optional.empty();
}

@Override
Expand Down
Loading

0 comments on commit 458c9ef

Please sign in to comment.