Fix appointment ownership
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
|
||||
public class AppointmentRequest {
|
||||
private List<Long> petIds;
|
||||
private List<Long> customerPetIds;
|
||||
private Long customerId;
|
||||
private Long storeId;
|
||||
private Long serviceId;
|
||||
@@ -24,6 +25,14 @@ public class AppointmentRequest {
|
||||
this.petIds = petIds;
|
||||
}
|
||||
|
||||
public List<Long> getCustomerPetIds() {
|
||||
return customerPetIds;
|
||||
}
|
||||
|
||||
public void setCustomerPetIds(List<Long> customerPetIds) {
|
||||
this.customerPetIds = customerPetIds;
|
||||
}
|
||||
|
||||
public Long getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ public class AppointmentResponse {
|
||||
private Long serviceId;
|
||||
private java.util.List<String> petNames;
|
||||
private java.util.List<Long> petIds;
|
||||
private java.util.List<String> customerPetNames;
|
||||
private java.util.List<Long> customerPetIds;
|
||||
private String serviceName;
|
||||
private LocalDate appointmentDate;
|
||||
private LocalTime appointmentTime;
|
||||
@@ -84,6 +86,22 @@ public class AppointmentResponse {
|
||||
this.petIds = petIds;
|
||||
}
|
||||
|
||||
public java.util.List<String> getCustomerPetNames() {
|
||||
return customerPetNames;
|
||||
}
|
||||
|
||||
public void setCustomerPetNames(java.util.List<String> customerPetNames) {
|
||||
this.customerPetNames = customerPetNames;
|
||||
}
|
||||
|
||||
public java.util.List<Long> getCustomerPetIds() {
|
||||
return customerPetIds;
|
||||
}
|
||||
|
||||
public void setCustomerPetIds(java.util.List<Long> customerPetIds) {
|
||||
this.customerPetIds = customerPetIds;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,14 @@ public class DropdownApi {
|
||||
return apiClient.getObjectMapper().readValue(response, new TypeReference<List<DropdownOption>>() {});
|
||||
}
|
||||
|
||||
public List<DropdownOption> getCustomerPets(Long customerId) throws Exception {
|
||||
String response = apiClient.getRawResponse("/api/v1/dropdowns/customers/" + customerId + "/pets");
|
||||
if (response == null || response.isEmpty()) {
|
||||
throw new IllegalStateException("Empty response from customer pets endpoint");
|
||||
}
|
||||
return apiClient.getObjectMapper().readValue(response, new TypeReference<List<DropdownOption>>() {});
|
||||
}
|
||||
|
||||
public List<DropdownOption> getStores() throws Exception {
|
||||
String response = apiClient.getRawResponse("/api/v1/dropdowns/stores");
|
||||
if (response == null || response.isEmpty()) {
|
||||
|
||||
@@ -233,13 +233,18 @@ public class AppointmentController {
|
||||
}
|
||||
|
||||
private AppointmentDTO mapToAppointmentDTO(AppointmentResponse response) {
|
||||
Long petId = response.getPetIds() != null && !response.getPetIds().isEmpty() ? response.getPetIds().get(0) : null;
|
||||
Long petId = response.getCustomerPetIds() != null && !response.getCustomerPetIds().isEmpty()
|
||||
? response.getCustomerPetIds().get(0)
|
||||
: response.getPetIds() != null && !response.getPetIds().isEmpty() ? response.getPetIds().get(0) : null;
|
||||
String petName = response.getCustomerPetNames() != null && !response.getCustomerPetNames().isEmpty()
|
||||
? String.join(", ", response.getCustomerPetNames())
|
||||
: String.join(", ", response.getPetNames());
|
||||
return new AppointmentDTO(
|
||||
response.getAppointmentId().intValue(),
|
||||
response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
|
||||
response.getCustomerName(),
|
||||
petId != null ? petId.intValue() : 0,
|
||||
String.join(", ", response.getPetNames()),
|
||||
petName,
|
||||
response.getServiceId() != null ? response.getServiceId().intValue() : 0,
|
||||
response.getServiceName(),
|
||||
response.getAppointmentDate().toString(),
|
||||
|
||||
@@ -50,6 +50,7 @@ public class AppointmentDialogController {
|
||||
|
||||
private String mode = null; // Add | Edit
|
||||
private AppointmentDTO selectedAppointment = null;
|
||||
private Long pendingPetSelectionId = null;
|
||||
|
||||
private ObservableList<String> statusList =
|
||||
FXCollections.observableArrayList(
|
||||
@@ -77,7 +78,6 @@ public class AppointmentDialogController {
|
||||
try {
|
||||
List<DropdownOption> services = DropdownApi.getInstance().getServices();
|
||||
List<DropdownOption> customers = DropdownApi.getInstance().getCustomers();
|
||||
List<DropdownOption> pets = DropdownApi.getInstance().getPets();
|
||||
|
||||
Platform.runLater(() -> {
|
||||
if (services != null) {
|
||||
@@ -86,9 +86,6 @@ public class AppointmentDialogController {
|
||||
if (customers != null) {
|
||||
cbCustomer.setItems(FXCollections.observableArrayList(customers));
|
||||
}
|
||||
if (pets != null) {
|
||||
cbPet.setItems(FXCollections.observableArrayList(pets));
|
||||
}
|
||||
syncSelectedAppointment();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
@@ -103,6 +100,7 @@ public class AppointmentDialogController {
|
||||
}).start();
|
||||
|
||||
cbAppointmentStatus.setItems(statusList);
|
||||
cbPet.setDisable(true);
|
||||
|
||||
// Hours 9 AM - 5 PM
|
||||
for (int i = 9; i <= 17; i++) {
|
||||
@@ -157,6 +155,18 @@ public class AppointmentDialogController {
|
||||
}
|
||||
});
|
||||
|
||||
cbCustomer.valueProperty().addListener((obs, oldValue, newValue) -> {
|
||||
Long customerId = newValue != null ? newValue.getId() : null;
|
||||
cbPet.setValue(null);
|
||||
cbPet.setItems(FXCollections.observableArrayList());
|
||||
cbPet.setDisable(customerId == null);
|
||||
if (customerId != null) {
|
||||
loadCustomerPets(customerId);
|
||||
} else {
|
||||
pendingPetSelectionId = null;
|
||||
}
|
||||
});
|
||||
|
||||
btnSave.setOnMouseClicked(this::buttonSaveClicked);
|
||||
btnCancel.setOnMouseClicked(this::closeStage);
|
||||
}
|
||||
@@ -199,11 +209,10 @@ public class AppointmentDialogController {
|
||||
});
|
||||
|
||||
cbCustomer.getItems().forEach(c -> {
|
||||
if (c.getId() != null && c.getId().longValue() == appt.getCustomerId()) cbCustomer.setValue(c);
|
||||
});
|
||||
|
||||
cbPet.getItems().forEach(p -> {
|
||||
if (p.getId() != null && p.getId().longValue() == appt.getPetId()) cbPet.setValue(p);
|
||||
if (c.getId() != null && c.getId().longValue() == appt.getCustomerId()) {
|
||||
pendingPetSelectionId = (long) appt.getPetId();
|
||||
cbCustomer.setValue(c);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -233,7 +242,7 @@ public class AppointmentDialogController {
|
||||
}
|
||||
|
||||
AppointmentRequest request = new AppointmentRequest();
|
||||
request.setPetIds(Collections.singletonList(cbPet.getValue().getId()));
|
||||
request.setCustomerPetIds(Collections.singletonList(cbPet.getValue().getId()));
|
||||
request.setCustomerId(cbCustomer.getValue().getId());
|
||||
request.setStoreId(storeId);
|
||||
request.setServiceId(cbService.getValue().getId());
|
||||
@@ -288,4 +297,34 @@ public class AppointmentDialogController {
|
||||
displayAppointmentDetails(selectedAppointment);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCustomerPets(Long customerId) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
List<DropdownOption> pets = DropdownApi.getInstance().getCustomerPets(customerId);
|
||||
Platform.runLater(() -> {
|
||||
cbPet.setItems(FXCollections.observableArrayList(pets));
|
||||
cbPet.setDisable(false);
|
||||
if (pendingPetSelectionId != null) {
|
||||
for (DropdownOption pet : cbPet.getItems()) {
|
||||
if (pet.getId() != null && pet.getId().equals(pendingPetSelectionId)) {
|
||||
cbPet.setValue(pet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pendingPetSelectionId = null;
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
Platform.runLater(() -> {
|
||||
ActivityLogger.getInstance().logException(
|
||||
"AppointmentDialogController.loadCustomerPets",
|
||||
ex,
|
||||
"Loading customer pets for appointment dialog");
|
||||
cbPet.setDisable(true);
|
||||
showError("Error loading pets for selected customer");
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user