Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#98 from wynonaK/delete
Browse files Browse the repository at this point in the history
Delete Appointments, Pet Patients and Owners & Updated Remove Useless Tags
  • Loading branch information
Aquarinte authored Mar 30, 2018
2 parents 585cca8 + 2a8dff3 commit 03660ae
Show file tree
Hide file tree
Showing 34 changed files with 920 additions and 103 deletions.
21 changes: 15 additions & 6 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,41 @@ Medeina will return `john` and `John Doe`
* Type in `find Betsy Tim John` +
Medeina will return any person having names `Betsy`, `Tim`, or `John`

=== Deleting a contact, pet patient or appointment : `delete` or `d`
=== Deleting a owner, pet patient or appointment : `delete` or `d` `[Since v1.3]`

Use the following command format to:

Delete an existing contact:: `delete **-o** INDEX`
Delete an existing owner:: `delete **-o** INDEX`
Forcefully deleting an existing owner:: `delete **-fo** INDEX`
Delete an existing pet patient:: `delete **-p** INDEX`
Forcefully deleting an existing pet patient:: `delete **-fp** INDEX`
Delete an existing appointment:: `delete **-a** INDEX`

****
* The command deletes the contact, pet patient or appointment at the specified `INDEX`.
* The commands -o and -p will not run if there are dependencies that rely on it. To forcefully delete, use the -fo and -fp options.
* Upon a forceful delete of an owner, all appointments and pet patients binded to the owner are automatically deleted as well.
* Upon a forceful delete of a pet patient, all appointments binded to the pet patient are automatically deleted as well.
* The index refers to the index number shown in the most recent listing, provided by the `list` command.
****

[IMPORTANT]
====
The index *must be a positive integer* `1, 2, 3, ...`
The index *must be a positive integer* and should not be *invalid* `1, 2, 3, ...`
====

Examples:

* Type in `list -o` +
`delete 2` +
Medeina will deletes the 2nd contact in Medeina's address book.
`delete -o 2` +
Medeina will deletes the 2nd owner in Medeina's address book only if there are no pet patients and appointments binded to that owner.

* Type in `list -o` +
`delete -fo 2` +
Medeina will deletes the 2nd owner in Medeina's address book, and all pet patients and appointments binded to that owner

* Type in `find -o Betsy` +
`d 1` +
`d -o 1` +
Medeina will delete the 1st contact in the results of the `find` command.

=== Selecting a contact : `select` or `s`
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(0, 6, 0, true);
public static final Version VERSION = new Version(1, 3, 17, true);

private static final Logger logger = LogsCenter.getLogger(MainApp.class);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_DISPLAYED_INDEX = "The index provided is invalid";
public static final String MESSAGE_DEPENDENCIES_EXIST = "Relevant dependencies still exist!";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_PET_PATIENT_DISPLAYED_INDEX = "The pet patient index "
+ "provided is invalid";
public static final String MESSAGE_INVALID_APPOINTMENT_DISPLAYED_INDEX = "The appointment index "
+ "provided is invalid";

public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
}
187 changes: 179 additions & 8 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,104 @@
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.appointment.exceptions.AppointmentDependencyNotEmptyException;
import seedu.address.model.appointment.exceptions.AppointmentNotFoundException;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.PersonNotFoundException;
import seedu.address.model.petpatient.PetPatient;
import seedu.address.model.petpatient.exceptions.PetDependencyNotEmptyException;
import seedu.address.model.petpatient.exceptions.PetPatientNotFoundException;

/**
* Deletes a person identified using it's last displayed index from the address book.
* Deletes a person, pet patient or appointment from the address book.
*/
public class DeleteCommand extends UndoableCommand {

public static final String COMMAND_WORD = "delete";
public static final String COMMAND_ALIAS = "d";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ " -[f]o/-[f]p/-a"
+ ": Deletes the person/pet/appointment identified by the index number used in the last listing.\n"
+ "Additional -[f] options indicates forcefully deleting object and all related dependencies.\n"
+ "Parameters: INDEX (must be a positive integer, must not be invalid)\n"
+ "Example: " + COMMAND_WORD + " -o 1";

public static final String MESSAGE_USAGE_OWNER = COMMAND_WORD
+ " -o"
+ ": Deletes the person identified by the index number used in the last person listing.\n"
+ "Parameters: INDEX (must be a positive integer, must not be invalid)\n"
+ "Example: " + COMMAND_WORD + " -o 1";

public static final String MESSAGE_USAGE_PET_PATIENT = COMMAND_WORD
+ " -p"
+ ": Deletes the pet patient identified by the index number used in the last pet patient listing.\n"
+ "Parameters: INDEX (must be a positive integer, must not be invalid)\n"
+ "Example: " + COMMAND_WORD + " -p 1";

public static final String MESSAGE_USAGE_APPOINTMENT = COMMAND_WORD
+ " -a"
+ ": Deletes the appointment identified by the index number used in the last appointment listing.\n"
+ "Parameters: INDEX (must be a positive integer, must not be invalid)\n"
+ "Example: " + COMMAND_WORD + " -a 1";

public static final String MESSAGE_USAGE_FORCE_OWNER = COMMAND_WORD
+ " -fo"
+ ": Forcefully deletes the person and all related dependencies "
+ "identified by the index number used in the last person listing.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";
+ "Example: " + COMMAND_WORD + " -fo 1";

public static final String MESSAGE_USAGE_FORCE_PET_PATIENT = COMMAND_WORD
+ " -fp"
+ ": Forcefully deletes the pet and all related dependencies "
+ "identified by the index number used in the last person listing.\n"
+ "Parameters: INDEX (must be a positive integer, must not be invalid)\n"
+ "Example: " + COMMAND_WORD + " -fp 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_PET_PATIENT_SUCCESS = "Deleted Pet Patient: %1$s";
public static final String MESSAGE_DELETE_APPOINTMENT_SUCCESS = "Deleted Appointment: %1$s";

private final Index targetIndex;
private final int type;

private Person personToDelete;
private PetPatient petPatientToDelete;
private Appointment appointmentToDelete;

public DeleteCommand(Index targetIndex) {
public DeleteCommand(int type, Index targetIndex) {
this.type = type;
this.targetIndex = targetIndex;
}


@Override
public CommandResult executeUndoableCommand() {
requireNonNull(personToDelete);
public CommandResult executeUndoableCommand() throws CommandException {
requireNonNull(model);
try {
switch (type) {
case 1: return deletePerson();
case 2: return deletePetPatient();
case 3: return deleteAppointment();
case 4: return deleteForcePerson();
case 5: return deleteForcePetPatient();
default:
throw new CommandException(MESSAGE_USAGE);
}
} catch (PetDependencyNotEmptyException e) {
throw new CommandException(Messages.MESSAGE_DEPENDENCIES_EXIST);
} catch (AppointmentDependencyNotEmptyException e) {
throw new CommandException(Messages.MESSAGE_DEPENDENCIES_EXIST);
}
}
/**
* Deletes {@code personToDelete} from the address book.
*/
private CommandResult deletePerson() throws PetDependencyNotEmptyException {
try {
requireNonNull(personToDelete);
model.deletePerson(personToDelete);
} catch (PersonNotFoundException pnfe) {
throw new AssertionError("The target person cannot be missing");
Expand All @@ -47,17 +114,121 @@ public CommandResult executeUndoableCommand() {
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
}

@Override
protected void preprocessUndoableCommand() throws CommandException {
private void getPersonToDelete() throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();

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

personToDelete = lastShownList.get(targetIndex.getZeroBased());
}

/**
* Deletes the pet patient {@code petPatientToDelete} from the address book.
*/
private CommandResult deletePetPatient() throws AppointmentDependencyNotEmptyException {
try {
requireNonNull(petPatientToDelete);
model.deletePetPatient(petPatientToDelete);
} catch (PetPatientNotFoundException ppnfe) {
throw new AssertionError("The target pet cannot be missing");
}

return new CommandResult(String.format(MESSAGE_DELETE_PET_PATIENT_SUCCESS, petPatientToDelete));
}

private void getPetPatientToDelete() throws CommandException {
List<PetPatient> lastShownList = model.getFilteredPetPatientList();

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

petPatientToDelete = lastShownList.get(targetIndex.getZeroBased());
}
/**
* Deletes the appointment {@code appointmentToDelete} from the address book.
*/
private CommandResult deleteAppointment() {
try {
requireNonNull(appointmentToDelete);
model.deleteAppointment(appointmentToDelete);
} catch (AppointmentNotFoundException anfe) {
throw new AssertionError("The target appointment cannot be missing");
}

return new CommandResult(String.format(MESSAGE_DELETE_APPOINTMENT_SUCCESS, appointmentToDelete));
}

private void getAppointmentToDelete() throws CommandException {
List<Appointment> lastShownList = model.getFilteredAppointmentList();

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

appointmentToDelete = lastShownList.get(targetIndex.getZeroBased());
}

/**
* Forcefully deletes {@code personToDelete} from the address book.
* All related dependencies (pet patients, appointments) will be deleted as well.
*/
private CommandResult deleteForcePerson() {
try {
requireNonNull(personToDelete);
model.deleteForcePerson(personToDelete);
} catch (PersonNotFoundException pnfe) {
throw new AssertionError("The target person cannot be missing");
} catch (AppointmentNotFoundException anfe) {
throw new AssertionError("The relevant appointments cannot be missing");
} catch (PetPatientNotFoundException ppnfe) {
throw new AssertionError("The relevant pet patients cannot be missing");
}

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
}

/**
* Forcefully deletes {@code petPatientToDelete} from the address book.
* All related dependencies (appointments) will be deleted as well.
*/
private CommandResult deleteForcePetPatient() {
try {
requireNonNull(petPatientToDelete);
model.deleteForcePetPatient(petPatientToDelete);
} catch (PetPatientNotFoundException ppnfe) {
throw new AssertionError("The target pet cannot be missing");
} catch (AppointmentNotFoundException anfe) {
throw new AssertionError("The relevant appointments cannot be missing");
}

return new CommandResult(String.format(MESSAGE_DELETE_PET_PATIENT_SUCCESS, petPatientToDelete));
}

@Override
protected void preprocessUndoableCommand() throws CommandException {
try {
switch (type) {
case 1: getPersonToDelete();
break;
case 2: getPetPatientToDelete();
break;
case 3: getAppointmentToDelete();
break;
case 4: getPersonToDelete();
break;
case 5: getPetPatientToDelete();
break;
default:
throw new CommandException(MESSAGE_USAGE);
}
} catch (CommandException e) {
throw new CommandException(Messages.MESSAGE_INVALID_DISPLAYED_INDEX);
}
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ protected void preprocessUndoableCommandForPerson() throws CommandException {

if (index.getZeroBased() >= lastShownPersonList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);

}

personToEdit = lastShownPersonList.get(index.getZeroBased());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CommandResult execute() throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();

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

EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex));
Expand Down
Loading

0 comments on commit 03660ae

Please sign in to comment.