From 2bb879eb9f27f7bbfb15f2d6c019ea5b2490ecc1 Mon Sep 17 00:00:00 2001 From: qyaner <> Date: Thu, 19 Oct 2023 11:42:34 +0800 Subject: [PATCH 1/4] add appointment-id --- .../logic/commands/AddAppointmentCommand.java | 1 + .../java/seedu/address/model/AddressBook.java | 21 +++++++++++++- .../address/model/ReadOnlyAddressBook.java | 6 ++++ .../model/appointments/Appointment.java | 29 +++++++++++++++++++ .../storage/JsonAdaptedAppointment.java | 13 +++++++-- .../storage/JsonSerializableAddressBook.java | 2 ++ .../seedu/address/ui/AppointmentCard.java | 3 ++ .../resources/view/AppointmentListCard.fxml | 1 + 8 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java b/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java index bb503958db2..a4172181c8d 100644 --- a/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java @@ -59,6 +59,7 @@ public AddAppointmentCommand(Appointment appointment) { */ @Override public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); if (model.hasAppointment(toAdd)) { throw new CommandException(MESSAGE_CLASHING_APPOINTMENTS); } diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 780949f06d9..986d60a5298 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -28,6 +28,7 @@ public class AddressBook implements ReadOnlyAddressBook { private long patientId; private long dentistId; + private long appointmentId; /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication @@ -83,6 +84,17 @@ public void incrementDentistId() { dentistId = dentistId + 1; } + public void setAppointmentId(long id) { + appointmentId = id; + } + @Override + public long getAppointmentId() { + return appointmentId; + } + public void incrementAppointmentId() { + appointmentId = appointmentId + 1; + } + //// list overwrite operations /** @@ -125,6 +137,7 @@ public void resetData(ReadOnlyAddressBook newData) { setAppointments(newData.getAppointmentList()); setPatientId(newData.getPatientId()); setDentistId(newData.getDentistId()); + setAppointmentId(newData.getAppointmentId()); } //// person-level operations @@ -205,7 +218,13 @@ public void addDentist(Dentist dentist) { } public void addAppointment(Appointment appointment) { - appointments.add(appointment); + if (appointment.getId() == -1) { + appointment.setId(appointmentId); + appointments.add(appointment); + incrementAppointmentId(); + } else { + appointments.add(appointment); + } } /** diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index 0af74bf99d9..b949c8ecdf4 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -41,4 +41,10 @@ public interface ReadOnlyAddressBook { * Returns an integer which represents the next available dentist id */ long getDentistId(); + + /** + * Returns an integer which represents the next available appointment id + */ + long getAppointmentId(); + } diff --git a/src/main/java/seedu/address/model/appointments/Appointment.java b/src/main/java/seedu/address/model/appointments/Appointment.java index 4b029ee7dab..3b05673b78a 100644 --- a/src/main/java/seedu/address/model/appointments/Appointment.java +++ b/src/main/java/seedu/address/model/appointments/Appointment.java @@ -9,6 +9,7 @@ public class Appointment { private final AppointmentTime appointmentTime; private final String duration; private final String treatment; + private long id; /** * Constructs an Appointment with the specified details. @@ -26,6 +27,26 @@ public Appointment(String dentist, String patient, AppointmentTime appointmentTi this.appointmentTime = appointmentTime; this.duration = duration; this.treatment = treatment; + this.id = -1; + } + + /** + * Constructs an Appointment with the specified details. + * + * @param dentist The name of the dentist for the appointment. + * @param patient The name of the patient for the appointment. + * @param appointmentTime The time and date of the appointment. + * @param duration The duration of the appointment. + * @param treatment The treatment provided. + */ + public Appointment(String dentist, String patient, AppointmentTime appointmentTime, + String duration, String treatment, long id) { + this.dentist = dentist; + this.patient = patient; + this.appointmentTime = appointmentTime; + this.duration = duration; + this.treatment = treatment; + this.id = id; } public String getDentist() { @@ -47,6 +68,14 @@ public AppointmentTime getAppointmentTime() { public String getTreatment() { return this.treatment; } + public void setId(long id) { + this.id = id; + } + + public long getId() { + return id; + } + /** * Checks whether this appointment clashes with another. diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java b/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java index 2833770e349..4280a49eb06 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java @@ -19,6 +19,7 @@ public class JsonAdaptedAppointment { private final String start; private final String duration; private final String treatment; + private final String id; /** * Constructs a {@code JsonAdaptedAppointment} with the given appointment details. @@ -32,12 +33,13 @@ public class JsonAdaptedAppointment { @JsonCreator public JsonAdaptedAppointment(@JsonProperty("dentist") String dentist, @JsonProperty("patient") String patient, @JsonProperty("start") String start, @JsonProperty("duration") String duration, - @JsonProperty("treatment") String treatment) { + @JsonProperty("treatment") String treatment, @JsonProperty("id") String id) { this.dentist = dentist; this.patient = patient; this.start = start; this.duration = duration; this.treatment = treatment; + this.id = id; } @@ -52,6 +54,7 @@ public JsonAdaptedAppointment(Appointment source) { start = source.getAppointmentTime().startToString(); duration = source.getAppointmentTime().durationToString(); treatment = source.getTreatment(); + id = String.valueOf(source.getId()); } /** @@ -81,7 +84,13 @@ public Appointment toModelType() throws IllegalValueException { throw new IllegalValueException( String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } + if (id == null) { + throw new IllegalValueException( + "id value does not exist!"); + } + long lid = Long.parseLong(id); + final AppointmentTime appointmentTime = new AppointmentTime(start, duration); - return new Appointment(dentist, patient, appointmentTime, duration, treatment); + return new Appointment(dentist, patient, appointmentTime, duration, treatment, lid); } } diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 54bcadd0a6f..a748e833ce0 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -34,6 +34,7 @@ class JsonSerializableAddressBook { private String patientId; private String dentistId; + private String appointmentId; @@ -60,6 +61,7 @@ public JsonSerializableAddressBook(ReadOnlyAddressBook source) { patientId = String.valueOf(source.getPatientId()); dentistId = String.valueOf(source.getDentistId()); + appointmentId = String.valueOf(source.getAppointmentId()); } /** diff --git a/src/main/java/seedu/address/ui/AppointmentCard.java b/src/main/java/seedu/address/ui/AppointmentCard.java index 064575c0cdd..98e656cddea 100644 --- a/src/main/java/seedu/address/ui/AppointmentCard.java +++ b/src/main/java/seedu/address/ui/AppointmentCard.java @@ -26,6 +26,8 @@ public class AppointmentCard extends UiPart { private Label date; @FXML private Label service; + @FXML + private Label appointmentId; /** * Constructs an {@code AppointmentCard} with the given {@code Appointment}. @@ -40,5 +42,6 @@ public AppointmentCard(Appointment appointment) { appointmentTime.setText(appointment.getAppointmentTime().appointmentTimeToString()); date.setText(appointment.getAppointmentTime().dateToString()); service.setText("Treatment: " + appointment.getTreatment()); + appointmentId.setText("Appointment ID: " + String.valueOf(appointment.getId())); } } diff --git a/src/main/resources/view/AppointmentListCard.fxml b/src/main/resources/view/AppointmentListCard.fxml index 0772bca1c7c..a206c3a6676 100644 --- a/src/main/resources/view/AppointmentListCard.fxml +++ b/src/main/resources/view/AppointmentListCard.fxml @@ -33,6 +33,7 @@