Fix desktop chat

This commit is contained in:
2026-04-08 08:38:23 -06:00
parent 559f3bc343
commit 8fb4c82a67
5 changed files with 48 additions and 21 deletions

View File

@@ -10,7 +10,9 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@RestController @RestController
@@ -24,12 +26,14 @@ public class DropdownController {
private final StoreRepository storeRepository; private final StoreRepository storeRepository;
private final SupplierRepository supplierRepository; private final SupplierRepository supplierRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final AdoptionRepository adoptionRepository;
public DropdownController(PetRepository petRepository, public DropdownController(PetRepository petRepository,
ServiceRepository serviceRepository, ProductRepository productRepository, ServiceRepository serviceRepository, ProductRepository productRepository,
CategoryRepository categoryRepository, StoreRepository storeRepository, CategoryRepository categoryRepository, StoreRepository storeRepository,
SupplierRepository supplierRepository, SupplierRepository supplierRepository,
UserRepository userRepository) { UserRepository userRepository,
AdoptionRepository adoptionRepository) {
this.petRepository = petRepository; this.petRepository = petRepository;
this.serviceRepository = serviceRepository; this.serviceRepository = serviceRepository;
this.productRepository = productRepository; this.productRepository = productRepository;
@@ -37,6 +41,7 @@ public class DropdownController {
this.storeRepository = storeRepository; this.storeRepository = storeRepository;
this.supplierRepository = supplierRepository; this.supplierRepository = supplierRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
this.adoptionRepository = adoptionRepository;
} }
@GetMapping("/pets") @GetMapping("/pets")
@@ -71,8 +76,19 @@ public class DropdownController {
@GetMapping("/appointment-customers") @GetMapping("/appointment-customers")
@PreAuthorize("hasAnyRole('STAFF', 'ADMIN')") @PreAuthorize("hasAnyRole('STAFF', 'ADMIN')")
public ResponseEntity<List<DropdownOption>> getAppointmentCustomers() { public ResponseEntity<List<DropdownOption>> getAppointmentCustomers() {
Set<Long> ownersWithPets = petRepository.findAll().stream()
.filter(p -> p.getOwner() != null)
.map(p -> p.getOwner().getId())
.collect(Collectors.toSet());
Set<Long> customersWithAdoptions = adoptionRepository.findAll().stream()
.filter(a -> "Completed".equalsIgnoreCase(a.getAdoptionStatus()))
.map(a -> a.getCustomer().getId())
.collect(Collectors.toSet());
Set<Long> customersWithPets = new HashSet<>(ownersWithPets);
customersWithPets.addAll(customersWithAdoptions);
return ResponseEntity.ok( return ResponseEntity.ok(
userRepository.findByRoleAndActiveTrue(User.Role.CUSTOMER).stream() userRepository.findByRoleAndActiveTrue(User.Role.CUSTOMER).stream()
.filter(u -> customersWithPets.contains(u.getId()))
.map(u -> new DropdownOption(u.getId(), u.getFirstName() + " " + u.getLastName())) .map(u -> new DropdownOption(u.getId(), u.getFirstName() + " " + u.getLastName()))
.collect(Collectors.toList()) .collect(Collectors.toList())
); );
@@ -156,11 +172,16 @@ public class DropdownController {
@GetMapping("/customers/{customerId}/pets") @GetMapping("/customers/{customerId}/pets")
@PreAuthorize("hasAnyRole('STAFF', 'ADMIN')") @PreAuthorize("hasAnyRole('STAFF', 'ADMIN')")
public ResponseEntity<List<DropdownOption>> getCustomerPets(@PathVariable Long customerId) { public ResponseEntity<List<DropdownOption>> getCustomerPets(@PathVariable Long customerId) {
return ResponseEntity.ok( Set<Long> seen = new HashSet<>();
petRepository.findAllByOwner_IdOrderByPetNameAsc(customerId).stream() List<DropdownOption> pets = new java.util.ArrayList<>();
petRepository.findAllByOwner_IdOrderByPetNameAsc(customerId).stream()
.map(p -> new DropdownOption(p.getPetId(), p.getPetName())) .map(p -> new DropdownOption(p.getPetId(), p.getPetName()))
.collect(Collectors.toList()) .forEach(o -> { if (seen.add(o.getId())) pets.add(o); });
); adoptionRepository.findByCustomer_IdAndAdoptionStatusIgnoreCase(customerId, "Completed").stream()
.map(a -> new DropdownOption(a.getPet().getPetId(), a.getPet().getPetName()))
.forEach(o -> { if (seen.add(o.getId())) pets.add(o); });
pets.sort(java.util.Comparator.comparing(DropdownOption::getLabel, String.CASE_INSENSITIVE_ORDER));
return ResponseEntity.ok(pets);
} }
@GetMapping("/suppliers") @GetMapping("/suppliers")

View File

@@ -9,6 +9,7 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
import java.util.Optional; import java.util.Optional;
@Repository @Repository
@@ -37,4 +38,6 @@ public interface AdoptionRepository extends JpaRepository<Adoption, Long> {
boolean existsByPet_IdAndAdoptionStatusIgnoreCaseAndAdoptionIdNot(Long petId, String adoptionStatus, Long adoptionId); boolean existsByPet_IdAndAdoptionStatusIgnoreCaseAndAdoptionIdNot(Long petId, String adoptionStatus, Long adoptionId);
boolean existsByPet_IdAndAdoptionStatusIgnoreCase(Long petId, String adoptionStatus); boolean existsByPet_IdAndAdoptionStatusIgnoreCase(Long petId, String adoptionStatus);
List<Adoption> findByCustomer_IdAndAdoptionStatusIgnoreCase(Long customerId, String adoptionStatus);
} }

View File

@@ -241,16 +241,16 @@ public class AppointmentController {
return new AppointmentDTO( return new AppointmentDTO(
response.getAppointmentId().intValue(), response.getAppointmentId().intValue(),
response.getCustomerId() != null ? response.getCustomerId().intValue() : 0, response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
response.getCustomerName(), response.getCustomerName() != null ? response.getCustomerName() : "",
response.getPetId() != null ? response.getPetId().intValue() : 0, response.getPetId() != null ? response.getPetId().intValue() : 0,
response.getPetName(), response.getPetName() != null ? response.getPetName() : "",
response.getServiceId() != null ? response.getServiceId().intValue() : 0, response.getServiceId() != null ? response.getServiceId().intValue() : 0,
response.getServiceName(), response.getServiceName() != null ? response.getServiceName() : "",
response.getEmployeeId() != null ? response.getEmployeeId().intValue() : 0, response.getEmployeeId() != null ? response.getEmployeeId().intValue() : 0,
response.getEmployeeName(), response.getEmployeeName() != null ? response.getEmployeeName() : "",
response.getAppointmentDate().toString(), response.getAppointmentDate() != null ? response.getAppointmentDate().toString() : "",
response.getAppointmentTime().toString(), response.getAppointmentTime() != null ? response.getAppointmentTime().toString() : "",
response.getAppointmentStatus() response.getAppointmentStatus() != null ? response.getAppointmentStatus() : ""
); );
} }
} }

View File

@@ -105,7 +105,12 @@ public class ChatController {
}); });
realtimeClient.setConversationListener(conversation -> Platform.runLater(() -> upsertConversation(conversation))); realtimeClient.setConversationListener(conversation -> Platform.runLater(() -> upsertConversation(conversation)));
realtimeClient.setMessageListener(message -> Platform.runLater(() -> appendMessageIfSelected(message))); realtimeClient.setMessageListener(message -> Platform.runLater(() -> {
Long myId = UserSession.getInstance().getUserId();
if (message.getSenderId() == null || !message.getSenderId().equals(myId)) {
appendMessageIfSelected(message);
}
}));
realtimeClient.setStatusListener(status -> Platform.runLater(() -> lblChatStatus.setText(status))); realtimeClient.setStatusListener(status -> Platform.runLater(() -> lblChatStatus.setText(status)));
realtimeClient.subscribeToConversations(); realtimeClient.subscribeToConversations();
@@ -208,9 +213,7 @@ public class ChatController {
MessageResponse response = ChatApi.getInstance().sendMessage(conversationId, new MessageRequest(content)); MessageResponse response = ChatApi.getInstance().sendMessage(conversationId, new MessageRequest(content));
Platform.runLater(() -> { Platform.runLater(() -> {
btnSend.setDisable(false); btnSend.setDisable(false);
if (!realtimeClient.isConnected()) { appendMessageIfSelected(response);
appendMessageIfSelected(response);
}
if (selectedConversation != null && selectedConversation.getId().equals(conversationId)) { if (selectedConversation != null && selectedConversation.getId().equals(conversationId)) {
lblChatStatus.setText("Message sent"); lblChatStatus.setText("Message sent");
} }

View File

@@ -327,12 +327,12 @@ public class PetController {
private Pet mapToPet(PetResponse response) { private Pet mapToPet(PetResponse response) {
Pet pet = new Pet( Pet pet = new Pet(
response.getPetId().intValue(), response.getPetId().intValue(),
response.getPetName(), response.getPetName() != null ? response.getPetName() : "",
response.getPetSpecies(), response.getPetSpecies() != null ? response.getPetSpecies() : "",
response.getPetBreed(), response.getPetBreed() != null ? response.getPetBreed() : "",
response.getPetAge() != null ? response.getPetAge() : 0, response.getPetAge() != null ? response.getPetAge() : 0,
response.getPetStatus(), response.getPetStatus() != null ? response.getPetStatus() : "",
response.getPetPrice().doubleValue(), response.getPetPrice() != null ? response.getPetPrice().doubleValue() : 0.0,
response.getImageUrl() response.getImageUrl()
); );
pet.setCustomerName(response.getCustomerName()); pet.setCustomerName(response.getCustomerName());