diff --git a/android/app/src/main/java/com/example/petstoremobile/adapters/AppointmentAdapter.java b/android/app/src/main/java/com/example/petstoremobile/adapters/AppointmentAdapter.java index 9960b5b6..fb260541 100644 --- a/android/app/src/main/java/com/example/petstoremobile/adapters/AppointmentAdapter.java +++ b/android/app/src/main/java/com/example/petstoremobile/adapters/AppointmentAdapter.java @@ -59,14 +59,14 @@ public class AppointmentAdapter extends RecyclerView.Adapter petNames; - private List petIds; + private String petName; + private Long petId; private String createdAt; private String updatedAt; public AppointmentDTO(Long customerId, Long storeId, Long serviceId, String appointmentDate, String appointmentTime, - String appointmentStatus, List petIds) { - this(customerId, storeId, serviceId, null, appointmentDate, appointmentTime, appointmentStatus, petIds); + String appointmentStatus, Long petId) { + this(customerId, storeId, serviceId, null, appointmentDate, appointmentTime, appointmentStatus, petId); } public AppointmentDTO(Long customerId, Long storeId, Long serviceId, Long employeeId, String appointmentDate, String appointmentTime, - String appointmentStatus, List petIds) { + String appointmentStatus, Long petId) { this.customerId = customerId; this.storeId = storeId; this.serviceId = serviceId; @@ -38,7 +35,7 @@ public class AppointmentDTO { this.appointmentDate = appointmentDate; this.appointmentTime = appointmentTime; this.appointmentStatus = appointmentStatus; - this.petIds = petIds; + this.petId = petId; } public Long getAppointmentId() { @@ -89,12 +86,12 @@ public class AppointmentDTO { return appointmentStatus; } - public List getPetNames() { - return petNames; + public String getPetName() { + return petName; } - public List getPetIds() { - return petIds; + public Long getPetId() { + return petId; } public String getCreatedAt() { @@ -105,16 +102,8 @@ public class AppointmentDTO { return updatedAt; } - public String getPetName() { - return (petNames != null && !petNames.isEmpty()) ? petNames.get(0) : ""; - } - public Long getPetID() { - return (petIds != null && !petIds.isEmpty()) ? petIds.get(0) : null; - } - - public Long getPetId() { - return getPetID(); + return petId; } public String getServiceType() { diff --git a/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/AppointmentDetailFragment.java b/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/AppointmentDetailFragment.java index d497f529..cf9bb837 100644 --- a/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/AppointmentDetailFragment.java +++ b/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/AppointmentDetailFragment.java @@ -48,7 +48,6 @@ public class AppointmentDetailFragment extends Fragment { private final Integer[] HOURS = {9,10,11,12,13,14,15,16,17}; private final Integer[] MINUTES = {0,15,30,45}; - private final String[] STATUSES = {"Booked","Completed","Cancelled"}; private AppointmentViewModel appointmentViewModel; private PetViewModel petViewModel; @@ -95,7 +94,8 @@ public class AppointmentDetailFragment extends Fragment { * Configures the adapters for spinners. */ private void setupSpinners() { - SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAppointmentStatus, STATUSES); + SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAppointmentStatus, + new String[]{"Booked", "Completed", "Cancelled", "Missed"}); String[] hours = new String[HOURS.length]; for (int i = 0; i < HOURS.length; i++) @@ -243,7 +243,7 @@ public class AppointmentDetailFragment extends Fragment { if (resource == null) return; if (resource.status == Resource.Status.SUCCESS && resource.data != null) { AppointmentDTO a = resource.data; - preselectedPetId = (a.getPetID() != null) ? a.getPetID() : -1; + preselectedPetId = (a.getPetId() != null) ? a.getPetId() : -1; preselectedServiceId = (a.getServiceId() != null) ? a.getServiceId() : -1; preselectedCustomerId = (a.getCustomerId() != null) ? a.getCustomerId() : -1; preselectedStoreId = (a.getStoreId() != null) ? a.getStoreId() : -1; @@ -265,7 +265,12 @@ public class AppointmentDetailFragment extends Fragment { } catch (NumberFormatException ignored) {} } - SpinnerUtils.setSelectionByValue(binding.spinnerAppointmentStatus, a.getAppointmentStatus()); + // Match Title labels with backend values + String status = a.getAppointmentStatus(); + if (status != null && !status.isEmpty()) { + String formattedStatus = status.substring(0, 1).toUpperCase() + status.substring(1).toLowerCase(); + SpinnerUtils.setSelectionByValue(binding.spinnerAppointmentStatus, formattedStatus); + } refreshPetSpinner(); refreshServiceSpinner(); @@ -306,11 +311,13 @@ public class AppointmentDetailFragment extends Fragment { String time = String.format("%02d:%02d", HOURS[binding.spinnerHour.getSelectedItemPosition()], MINUTES[binding.spinnerMinute.getSelectedItemPosition()]); - String status = STATUSES[binding.spinnerAppointmentStatus.getSelectedItemPosition()]; + + // Get status and convert to uppercase for backend + String status = binding.spinnerAppointmentStatus.getSelectedItem().toString().toUpperCase(); - // Validate future date+time if status is Booked - if ("Booked".equalsIgnoreCase(status)) { + // Validate future date+time if status is BOOKED + if ("BOOKED".equalsIgnoreCase(status)) { try { String[] dateParts = date.split("-"); String[] timeParts = time.split(":"); @@ -342,7 +349,7 @@ public class AppointmentDetailFragment extends Fragment { date, time, status, - Collections.singletonList(pet.getPetId()) + pet.getPetId() ); androidx.lifecycle.Observer> observer = resource -> {