Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#113 from wynonaK/uniqueAppoint…
Browse files Browse the repository at this point in the history
…ment

Appointments are unique based on datetime.
  • Loading branch information
Aquarinte committed Mar 30, 2018
2 parents 03660ae + e339138 commit 08f122a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.appointment.exceptions.DuplicateAppointmentException;
import seedu.address.model.appointment.exceptions.DuplicateDateTimeException;
import seedu.address.model.person.Nric;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.DuplicateNricException;
Expand Down Expand Up @@ -114,6 +115,7 @@ public class AddCommand extends UndoableCommand {
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in Medeina.";
public static final String MESSAGE_DUPLICATE_NRIC = "This is already someone with this NRIC.";
public static final String MESSAGE_DUPLICATE_APPOINTMENT = "This particular appointment already exists in Medeina.";
public static final String MESSAGE_DUPLICATE_DATETIME = "This date time is already taken by another appointment.";
public static final String MESSAGE_DUPLICATE_PET_PATIENT = "This pet patient already exists in Medeina";
public static final String MESSAGE_INVALID_NRIC = "The specified NRIC does not belong to anyone in Medeina."
+ " Please add a new person.";
Expand Down Expand Up @@ -204,6 +206,8 @@ public CommandResult executeUndoableCommand() throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_PET_PATIENT);
} catch (DuplicateAppointmentException e) {
throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT);
} catch (DuplicateDateTimeException e) {
throw new CommandException(MESSAGE_DUPLICATE_DATETIME);
}
}

Expand All @@ -228,7 +232,8 @@ private CommandResult addNewPetPatient() throws DuplicatePetPatientException, Co
/**
* Add a new appointment for an existing pet patient under an existing person.
*/
private CommandResult addNewAppt() throws CommandException, DuplicateAppointmentException {
private CommandResult addNewAppt()
throws CommandException, DuplicateAppointmentException, DuplicateDateTimeException {
Person owner = getPersonWithNric();
PetPatient pet = getPetPatientWithNricAndName();
if (owner != null) {
Expand All @@ -253,7 +258,7 @@ private CommandResult addNewAppt() throws CommandException, DuplicateAppointment
* (New appointment for the new patient under a new person).
*/
private CommandResult addAllNew() throws DuplicatePersonException, DuplicateNricException,
DuplicatePetPatientException, DuplicateAppointmentException {
DuplicatePetPatientException, DuplicateAppointmentException, DuplicateDateTimeException {
model.addPerson(toAddOwner);
model.addPetPatient(toAddPet);
model.addAppointment(toAddAppt);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.model.appointment.exceptions.AppointmentDependencyNotEmptyException;
import seedu.address.model.appointment.exceptions.AppointmentNotFoundException;
import seedu.address.model.appointment.exceptions.DuplicateAppointmentException;
import seedu.address.model.appointment.exceptions.DuplicateDateTimeException;
import seedu.address.model.person.Person;
import seedu.address.model.person.UniquePersonList;
import seedu.address.model.person.exceptions.DuplicateNricException;
Expand Down Expand Up @@ -76,7 +77,8 @@ public void setTags(Set<Tag> tags) {
this.tags.setTags(tags);
}

public void setAppointments(List<Appointment> appointments) throws DuplicateAppointmentException {
public void setAppointments(List<Appointment> appointments)
throws DuplicateAppointmentException, DuplicateDateTimeException {
this.appointments.setAppointments(appointments);
}

Expand Down Expand Up @@ -109,6 +111,8 @@ public void resetData(ReadOnlyAddressBook newData) {
try {
setAppointments(syncedAppointmentList);
} catch (DuplicateAppointmentException dae) {
throw new AssertionError("AddressBook should not have duplicate appointments.");
} catch (DuplicateDateTimeException ddte) {
throw new AssertionError("AddressBook should not have appointments on the same slot");
}

Expand Down Expand Up @@ -169,7 +173,7 @@ public void updatePerson(Person target, Person editedPerson)
*
* @throws DuplicateAppointmentException if an equivalent person already exists.
*/
public void addAppointment(Appointment a) throws DuplicateAppointmentException {
public void addAppointment(Appointment a) throws DuplicateAppointmentException, DuplicateDateTimeException {
Appointment appointment = syncWithAppointmentMasterTagList(a);
// TODO: the tags master list will be updated even though the below line fails.
// This can cause the tags master list to have additional tags that are not tagged to any appointment
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.address.model.appointment.exceptions.AppointmentDependencyNotEmptyException;
import seedu.address.model.appointment.exceptions.AppointmentNotFoundException;
import seedu.address.model.appointment.exceptions.DuplicateAppointmentException;
import seedu.address.model.appointment.exceptions.DuplicateDateTimeException;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.DuplicateNricException;
import seedu.address.model.person.exceptions.DuplicatePersonException;
Expand Down Expand Up @@ -56,7 +57,7 @@ void updatePerson(Person target, Person editedPerson)
void deleteTag(Tag tag);

/** Adds the given appointment */
void addAppointment(Appointment appointment) throws DuplicateAppointmentException;
void addAppointment(Appointment appointment) throws DuplicateAppointmentException, DuplicateDateTimeException;

/** Deletes the given appointment. */
void deleteAppointment(Appointment target) throws AppointmentNotFoundException;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.model.appointment.exceptions.AppointmentDependencyNotEmptyException;
import seedu.address.model.appointment.exceptions.AppointmentNotFoundException;
import seedu.address.model.appointment.exceptions.DuplicateAppointmentException;
import seedu.address.model.appointment.exceptions.DuplicateDateTimeException;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.DuplicateNricException;
import seedu.address.model.person.exceptions.DuplicatePersonException;
Expand Down Expand Up @@ -131,7 +132,8 @@ public synchronized void deleteAppointment(Appointment target) throws Appointmen
}

@Override
public synchronized void addAppointment(Appointment appointment) throws DuplicateAppointmentException {
public synchronized void addAppointment(Appointment appointment)
throws DuplicateAppointmentException, DuplicateDateTimeException {
addressBook.addAppointment(appointment);
updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS);
indicateAddressBookChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.collections.ObservableList;
import seedu.address.model.appointment.exceptions.AppointmentNotFoundException;
import seedu.address.model.appointment.exceptions.DuplicateAppointmentException;
import seedu.address.model.appointment.exceptions.DuplicateDateTimeException;

/**
* A list of appointments that enforces uniqueness between its elements and does not allow nulls.
Expand All @@ -35,11 +36,17 @@ public boolean contains(Appointment toCheck) {
*
* @throws DuplicateAppointmentException if the person to add is a duplicate of an existing person in the list.
*/
public void add(Appointment toAdd) throws DuplicateAppointmentException {
public void add(Appointment toAdd) throws DuplicateAppointmentException, DuplicateDateTimeException {
requireNonNull(toAdd);
if (contains(toAdd)) {
throw new DuplicateAppointmentException();
}

for (Appointment a : internalList) {
if (a.getDateTime().equals(toAdd.getDateTime())) {
throw new DuplicateDateTimeException();
}
}
internalList.add(toAdd);
}

Expand Down Expand Up @@ -84,7 +91,8 @@ public void setAppointments(UniqueAppointmentList replacement) {
this.internalList.setAll(replacement.internalList);
}

public void setAppointments(List<Appointment> appointments) throws DuplicateAppointmentException {
public void setAppointments(List<Appointment> appointments)
throws DuplicateAppointmentException, DuplicateDateTimeException {
requireAllNonNull(appointments);
final UniqueAppointmentList replacement = new UniqueAppointmentList();
for (final Appointment appointment : appointments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/
public class DuplicateAppointmentException extends DuplicateDataException {
public DuplicateAppointmentException() {
super("Operation would result in duplicate persons");
super("Operation would result in duplicate appointments");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package seedu.address.model.appointment.exceptions;

import seedu.address.commons.exceptions.DuplicateDataException;

/**
* Signals that the operation will result in double booking.
*/
public class DuplicateDateTimeException extends DuplicateDataException {
public DuplicateDateTimeException() {
super("Operation would result in multiple bookings in the same time slot");
}
}

0 comments on commit 08f122a

Please sign in to comment.